There is a Javascript/Jquery boolean function to test if a string is all uppercase?
example of matching:
"hello" => false
"Hello" => false
"HELLO" => true
There is a Javascript/Jquery boolean function to test if a string is all uppercase?
example of matching:
"hello" => false
"Hello" => false
"HELLO" => true
function isUpperCase(str) {
return str === str.toUpperCase();
}
isUpperCase("hello"); // false
isUpperCase("Hello"); // false
isUpperCase("HELLO"); // true
You could also augment String.prototype
:
String.prototype.isUpperCase = function() {
return this.valueOf().toUpperCase() === this.valueOf();
};
"Hello".isUpperCase(); // false
"HELLO".isUpperCase(); // true
I must write at least one sentence here because they don't like short answers here, but this is the simplest solution I can think of:
s.toUpperCase() === s
Here's another option:
function isUpperCase(str) {
return (/^[^a-z]*$/).test(str);
}
var test = "HELLO";
var upper = test.toUpperCase();
return test === upper; // true
// other example
var test = "Hello";
var upper = test.toUpperCase();
return test === upper; // false