|
||||||||||||||||||||
|
Java Frequently Ask Question How to check if a string contain a mix cases? by Puthyrak Kang September, 2009There are plenty way of doing this. One way is using Java regular expression to check if the string under question does not contain any lower-case character or any upper-case character. Try the following code.
/**
* Verifies that the entry has at least one upper-case and one lower-case character.
* Dot (".") is treated as a lower-case character
*/
public static boolean isMixedCase( String strValue_p ) {
if( strValue_p.length() > 0 ) {
if( ! strValue_p.matches( ".*[a-z.]+.*" ) ) {
return false;
}
if( ! strValue_p.matches( ".*[A-Z]+.*" ) ) {
return false;
}
}
return true;
}
|
||||||||||||||||||||
|
||||||||||||||||||||