我需要一个匹配类似于此处的货币值的正则表达式:Regex for Money
即。 '1000','1000,0'和'1000,00'
但我需要使用javascript工作:
var RE = /^-{0,1}\d*\.{0,1}\d+$/; //validates decimal format such as 1000.50
if (locale == "fr") {
RE = \d+(?:,\d{1,2})? //this line fails when validated using the javascript below
}
return (RE.test(valueToValidate));
答案 0 :(得分:3)
javascript中的文字正则表达式应该围绕模式
定义/
var RE = /^-{0,1}\d*\.{0,1}\d+$/; //validates decimal format such as 1000.50
if (locale == "fr") {
RE = /\d+(?:,\d{1,2})?/ //this line fails when validated using the javascript below
}
return (RE.test(valueToValidate));
答案 1 :(得分:0)
只是语法检查:你是否忘记了第二次作业中的正斜杠?