Clue Mediator

Check if a String is in Uppercase or Lowercase in JavaScript

📅March 28, 2022

Converting a string to uppercase or lowercase is straightforward using the `toUpperCase()` or `toLowerCase()` methods. But here we will see how to check if a String is all UpperCase or Lowercase using JavaScript.

Checkout more articles on JavaScript

Ways to check if a String is all Uppercase or Lowercase

  1. Using regular expression
  2. Using toUpperCase or toLowerCase methods

1. Using regular expression

The Regular Expression is the best way to determine whether a string is in uppercase or lowercase. Use the following code.

const isUpperCase = str => /^[A-Z]*$/.test(str)

isUpperCase('CLUE') // true
isUpperCase('mediator') // false

2. Using toUpperCase or toLowerCase methods

We can also use the predefined function toUpperCase() to check the string.

function isUpperCase (input) {
  return input === String(input).toUpperCase()
}

isUpperCase('CLUE') // true
isUpperCase('mediator') // false

That’s it for today.
Thank you for reading. Happy Coding..!! 🙂