Checks if the String contains only unicode letters or digits.
* *null
will return false
.
* An empty String ("") will return true
.
* StringUtils.isAlphanumeric(null) = false * StringUtils.isAlphanumeric("") = true * StringUtils.isAlphanumeric(" ") = false * StringUtils.isAlphanumeric("abc") = true * StringUtils.isAlphanumeric("ab c") = false * StringUtils.isAlphanumeric("ab2c") = true * StringUtils.isAlphanumeric("ab-c") = false ** * @param str the String to check, may be null * @return
true
if only contains letters or digits,
* and is non-null
*/
public static boolean isAlphanumeric(String str) {
if (str == null) {
return false;
}
int sz = str.length();
for (int i = 0; i < sz; i++) {
if (Character.isLetterOrDigit(str.charAt(i)) == false) {
return false;
}
}
return true;
}
}