I need to test a character for uppercase only A-Z. Not any other special unicode or other languages.
I was reading the documentation for Character.isUpperCase. It seems like it would pass if it was a unicode character that was considered uppercase but not technically between A-Z. And it seems like it would pass uppercase characters from other languages besides english.
Do i just need to use regular expressions or am i reading into Character.isUpperCase incorrectly?
Thanks
From the documentation you linked:
Many other Unicode characters are uppercase too.
So yes, using isUpperCase
will match things other than A-Z.
One way to do the test though is like this.
boolean isUpperCaseEnglish(char c){
return c >= 'A' && c <= 'Z';
}
isUpperCase
indeed does not promise the character is between 'A'
and 'Z'
. You could use a regex:
String s = ...;
Pattern p = Pattern.compile("[A-Z]*");
Matcher m = p.matcher(s);
boolean matches = m.matches();
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