我一直在尋找一個JavaScript正則表達式模式,將允許在插入或註冊這些類型的量不爲金錢價值的JavaScript正則表達式模式沒有貨幣
5
5.1
5.10
5
500,000
500,000.1
500,000.10
,但這些數字不應該比0。我設法較小找到模式,但我想省略「$」。我要的是一個數字,逗號和點只有
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))
刪除\ $?來自RegEx –
新RegEx將/^\d+(,\d{3})*(\.\d*)?$/ –
我的回答有幫助嗎?考慮接受它,如果它。 – fuzz