Checks if the String contains only unicode letters, digits
* or space (' '
).
null
will return false
.
* An empty String ("") will return true
.
* StringUtils.isAlphanumeric(null) = false * StringUtils.isAlphanumeric("") = true * StringUtils.isAlphanumeric(" ") = true * StringUtils.isAlphanumeric("abc") = true * StringUtils.isAlphanumeric("ab c") = true * StringUtils.isAlphanumeric("ab2c") = true * StringUtils.isAlphanumeric("ab-c") = false ** * @param str the String to check, may be null * @return
true
if only contains letters, digits or space,
* and is non-null
*/
public static boolean isAlphanumericSpace(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) && (str.charAt(i) != ' ')) {
return false;
}
}
return true;
}
}