Home > Java > JavaBase > body text

Java verifies whether it is a number

Release: 2019-11-20 10:04:47
Original
2298 people have browsed it

Java verifies whether it is a number

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{
  //是数字
}
Copy after login

matches() method is used to detect whether a string matches a given regular expression.

Syntax

public boolean matches(String regex)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template