我有以下代码部分:
this.product.unitprice
.toLocaleString()
.substring(this.product.unitprice.toString().length-3)
.indexOf(',')==-1)我想检查一下,如果我有,00 ->只有这是有效的,任何其他都不是。有什么建议吗?
发布于 2018-01-25 13:18:23
使用这个regex ^\,[0-9]{2}$,它表示逗号,后面只有两个数字。
发布于 2018-01-25 13:00:06
我想这就是你需要的:
price = '1,00,250,00';
// just for the ,00 comparision
if(price.substr(price.length - 3) == ',00'){
console.log("Good to go");
} else {
console.log("Noooooooo");
}
// will check for ,xx (x=any digit)
var patt = new RegExp(",[0-9]{2}$");
if(patt.test(price)){
console.log("Good to go");
} else {
console.log("Noooooooo");
}
发布于 2018-01-25 13:02:56
price="1,000,000"
if(price.replace(/,[0-9][0-9]/,"")!=price){
console.log(true+"good")
}
else{
console.log(false)
}https://stackoverflow.com/questions/48443421
复制相似问题