HOWTO · JavaScript
How to Check if a Character in a String Is Uppercase or Not in JavaScript
This tutorial demonstrates how to check if all the characters in a given string are in an uppercase format or not in JavaScript.
On this page
JavaScript does not provide a built-in predicate that tells you whether every character in a string is already uppercase. You can compare each character with the result of its toUpperCase() method: a difference identifies a character that changes during conversion. The function below reports changed characters and returns a Boolean for each call.
Check Whether Every Character Is Uppercase
The check is based on whether uppercase conversion changes a character. That distinction matters: spaces, digits, and punctuation do not become letters, but they also remain unchanged and therefore pass this particular check. The function reports whether the input is unchanged by uppercasing; it does not prove that every character is a letter.
Build an isUpperCase() Function
Keep the status variable inside the function so each call starts with its own result. A for...of loop visits the string’s Unicode code points, and const keeps the loop variable local. When a character differs from its uppercase form, the function reports it and updates the result. It returns true only when no character changed.
Run this example:
function isUpperCase(providedStr) {
let allUpperCase = true;
for (const character of providedStr) {
if (character !== character.toUpperCase()) {
allUpperCase = false;
console.log(`Letter ${character} is not uppercase.`);
}
}
if (allUpperCase) {
console.log('No characters change when converted to uppercase.');
}
return allUpperCase;
}
const str_1 = 'AB% ^M';
const str_2 = 'IO(|12c';
isUpperCase(str_1);
isUpperCase(str_2);
The exact function name isUpperCase() is a user-defined name. The built-in toUpperCase() method supplies the comparison value; it does not modify the original string.
Read the Results
For AB% ^M, every code point compares equal to its uppercase form, so the function returns true and takes the success-message branch. The percent sign, space, caret, and M are unchanged; this shows why an unchanged-character check is not the same as a letters-only validation.
For IO(|12c, the lowercase c differs from its uppercase form. The function reports that character, continues checking the rest of the string, and returns false. It does not stop at the first change, so if more than one character changes, each changed character is reported. Callers can use the return value in a conditional or assign it to a variable instead of relying on the messages. The messages are optional; remove the console.log() calls if the function should only return a Boolean.
Understand Empty Strings and Character Limits
An empty string passes this unchanged-by-uppercase test: its loop has no characters to compare, so allUpperCase remains true and the function returns true. Decide separately whether that result suits your application. For example, a form that requires at least one uppercase letter should check the string’s length or presence of a letter in addition to this predicate.
The name isUpperCase() is convenient, but the check has a narrower meaning than “contains only uppercase letters.” Whitespace, punctuation, and digits pass because their uppercase conversion leaves them unchanged. If your requirement is specifically about letters, first define which letters count and validate those separately.
Unicode adds another limitation: uppercasing can change the number of code points. For example, some lowercase characters convert to multiple uppercase characters. This function detects such a change, but that does not make it a complete Unicode case-classification or case-folding routine. Also, JavaScript strings are sequences of UTF-16 code units while for...of iterates code points; neither approach counts every user-perceived symbol as one character in all cases. Use a Unicode-aware library or a clearly defined character set when an application needs locale-specific or user-perceived-letter rules.