正则表达式判断字符串是否为数字 兼容整数、小数、正负数、点开头的小数
JavaScript语言
let match = /^[+-]{0,1}(([0-9]([0-9]*|[\.][0-9]+))|([\.][0-9]+))$/.test('+.2')
console.log(match)
Java语言
boolean match = "+.2".matches("^[+-]{0,1}(([0-9]([0-9]*|[\\.][0-9]+))|([\\.][0-9]+))$");
System.out.println(match);
其他语言
正则表达式:
^[+-]{0,1}(([0-9]([0-9]*|[\.][0-9]+))|([\.][0-9]+))$
本文来自博客园,作者:HumorChen99,转载请注明原文链接:https://www.cnblogs.com/HumorChen/p/18039585