I was looking for a javascript regex pattern that will allow inserting or registering these type of amount
5
5.1
5.10
5
500,000
500,000.1
500,000.10
but these numbers should not be lesser than 0. I managed to find pattern but I want to omit the "$". All I want is numbers,commas,and dots only
var x = 5000;
var a = "5,000,000"
var y = "$5,,,000,000"
var z = "500,000"
var c = "c231"
console.log(x," Valid", /^\$?\d+(,\d{3})*(\.\d*)?$/.test(x))
console.log(a," Valid", /^\$?\d+(,\d{3})*(\.\d*)?$/.test(a))
console.log(y," Valid", /^\$?\d+(,\d{3})*(\.\d*)?$/.test(y))
console.log(z," Valid", /^\$?\d+(,\d{3})*(\.\d*)?$/.test(z))
console.log(c," Valid", /^\$?\d+(,\d{3})*(\.\d*)?$/.test(c))
Remove the \\$?
/^\\d+(,\\d{3})*(\\.\\d*)?$/
var x = 5000; var a = "5,000,000" var y = "$5,,,000,000" var z = "500,000" var c = "c231" var d = "1...0.00" var e = "..." var f = "1.00,,," var validRegEx = /^\\d+(,\\d{3})*(\\.\\d*)?$/; console.log(x," Valid", validRegEx.test(x)) console.log(a," Valid", validRegEx.test(a)) console.log(y," Valid", validRegEx.test(y)) console.log(z," Valid", validRegEx.test(z)) console.log(c," Valid", validRegEx.test(c)) console.log(d," Valid", validRegEx.test(c)) console.log(e," Valid", validRegEx.test(c)) console.log(f," Valid", validRegEx.test(c))
Based on my Comment on Question the new code will be
var x = 5000;
var a = "5,000,000"
var y = "$5,,,000,000"
var z = "500,000"
var c = "c231"
console.log(x," Valid", /^\d+(,\d{3})*(\.\d*)?$/.test(x))
console.log(a," Valid", /^\d+(,\d{3})*(\.\d*)?$/.test(a))
console.log(y," Valid", /^\d+(,\d{3})*(\.\d*)?$/.test(y))
console.log(z," Valid", /^\d+(,\d{3})*(\.\d*)?$/.test(z))
console.log(c," Valid", /^\d+(,\d{3})*(\.\d*)?$/.test(c))
尝试
^\$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(\.[0-9][0-9])?$
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.