我试图使用正则表达式来验证十进制值.我写下面的正则表达式,但它不允许第一个小数点值为.5或.6或.1
常规Exp:/^\d[0-9]{0,13}(\.\d{1,2})?$/
规则:
示例 - 有效输入
示例 - 输入无效
const valid = [
"0",
"0.5",
"1.55",
".5",
"1234567890123",
"1234567890123.5",
"1234567890123.00",
];
const invalid = [
".",
".0",
"1.234",
"5.",
"12345678901234",
"12345678901234.56",
];
const rgx = /^\d[0-9]{0,13}(\.\d{1,2})?$/
console.log("Checking valid strings (should all be true):");
valid.forEach(str => console.log(rgx.test(str), str));
console.log("\nChecking invalid strings (should all be false):"); …
Run Code Online (Sandbox Code Playgroud)