Checks if the String contains only unicode digits or space
* (' '
).
* A decimal point is not a unicode digit and returns false.
null
will return false
.
* An empty String ("") will return true
.
* StringUtils.isNumeric(null) = false * StringUtils.isNumeric("") = true * StringUtils.isNumeric(" ") = true * StringUtils.isNumeric("123") = true * StringUtils.isNumeric("12 3") = true * StringUtils.isNumeric("ab2c") = false * StringUtils.isNumeric("12-3") = false * StringUtils.isNumeric("12.3") = false ** * @param str the String to check, may be null * @return
true
if only contains digits or space,
* and is non-null
*/
public static boolean isNumericSpace(String str) {
if (str == null) {
return false;
}
int sz = str.length();
for (int i = 0; i < sz; i++) {
if ((Character.isDigit(str.charAt(i)) == false) && (str.charAt(i) != ' ')) {
return false;
}
}
return true;
}
}