使用org.apache.commons.lang
org.apache.commons.lang.StringUtils;
boolean isNunicodeDigits=StringUtils.isNumeric("aaa123456789");
http://jakarta.apache.org/commons/lang/api-release/index.html下面的解释:
isNumeric
public static boolean isNumeric(String str)Checks if the String contains only unicode digits. 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(" ") = false
StringUtils.isNumeric("123") = true
StringUtils.isNumeric("12 3") = false
StringUtils.isNumeric("ab2c") = false
StringUtils.isNumeric("12-3") = false
StringUtils.isNumeric("12.3") = false
Parameters:
str - the String to check, may be null
Returns:
true if only contains digits, and is non-null
Among the above three methods, the second method is more flexible.
The first and third methods can only verify numbers without the negative sign "-", that is, if you enter a negative number -199, the output result will be false;
The second method can be used to verify negative numbers by modifying the regular expression. Just change the regular expression to "^-?[0-9]+" and change it to "-?[0-9]+.? [0-9]+" will match all numbers.
Among the above three methods, the second method is more flexible.
The first and third methods can only verify numbers without the negative sign "-", that is, if you enter a negative number -199, the output result will be false;
The second method can be used to verify negative numbers by modifying the regular expression. Just change the regular expression to "^-?[0-9]+" and change it to "-?[0-9]+.? [0-9]+" will match all numbers.