Regularly judge whether a string is a pure number

The regex is as follows: [-,+]?[0-9]+[.]?[0-9]+

String str ="12.23";
boolean matches = str.matches("[-,+]?[0-9]+[.]?[0-9]+");

This can check positive and negative integers and positive and negative decimals, but for 12. -12. this is not a number
 

Regular online verification website: Online regular expression test (oschina.net)

Validation checks are as follows

 

Guess you like

Origin blog.csdn.net/dhklsl/article/details/129283463