2012-01-18 59 views
2

我需要相匹配的貨幣在此值的類似正則表達式:Regex for Money爲逗號JavaScript正則表達式分隔小數

即「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

可能重複的[正則表達式爲貨幣](http://stackoverflow.com/questions/1028221/regex-for-money)在那裏發佈的正則表達式將沒有不同的JavaScript ... – Esailija 2012-01-18 15:44:49

+0

我不清楚什麼是什麼你想要正則表達式匹配和不匹配。 – jfriend00 2012-01-18 15:46:54

回答

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)); 
+0

感謝您使用javascript – FiveTools 2012-01-18 15:57:29

+0

時的/定義模式,您還可以選擇在尾部的'/'後面添加'i'和'g',以使模式不敏感或全局 – 2012-01-18 16:11:20

0

只是一個語法檢查:你在第二個任務中忘記了正斜槓嗎?

相關問題