Files
30-seconds-of-code/snippets/isUpperCase.md
Rohit Tanwar 19874c5689 isLowerCase
2018-01-06 14:46:39 +05:30

538 B

isUpperCase

Checks if the provided argument contains anything else than the uppercase alphabets. If the second argument is provided to be true than numbers and other symbols are considered uppercase too.

const isUpperCase = (val,symbol = false) => {
  if (symbol) return val === val.toUpperCase()
  else return!(/[^A-Z]/g.test(val))
}
isUpperCase('ABC'); //true
isUpperCase('ABC123@$'); //false
isUpperCase('ABC123@$',true); //true
isUpperCase('ABC123@$abcd',true); //false
isUpperCase('ABC123@$abcd'); //false