java determines whether it is a number:
int id = 12345689797; Pattern pattern = Pattern.compile("[0-9]*"); Matcher isNum = pattern.matcher(id); if( !isNum.matches() ){ //不是数字 }else{ //是数字 }
matches() method is used to detect whether a string matches a given regular expression.
Syntax
public boolean matches(String regex)
Parameters
regex -- Regular expression that matches strings.
Return value
Returns true when the string matches the given regular expression.
For more java knowledge, please pay attention to java basic tutorial.
The above is the detailed content of Java verifies whether it is a number. For more information, please follow other related articles on the PHP Chinese website!