There is a Javascript/Jquery boolean function to test if a string is all uppercase?
example of matching:
"hello" => false "Hello" => false "HELLO" => true
To check if a string is all uppercase, use the toUppercase() method to convert the string to uppercase and compare it to itself. If the comparison returns true , then the string is all uppercase.
To check if a string is in uppercase, we can use the isupper() method. isupper() checks whether every case-based character in a string is in uppercase, and returns a True or False value depending on the outcome.
upper() Return Value upper() method returns the uppercase string from the given string. It converts all lowercase characters to uppercase.
The toUpperCase() method converts a string to uppercase letters. The toUpperCase() method does not change the original string.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With