2015-04-28 44 views
1

貨幣要求的格式看起來像ASP.NET貨幣正則表達式

1,100,258 
100,258 
23,258 
3,258 

或者像 1234562421323等所有整數。

ValidationExpression

(^[0-9]{1,3}(,\d{3})*) | (^[0-9][0-9]*) 

以下類型,但它不工作。

回答

1

您有ignore pattern whitespace嗎?如果沒有,請移除管道兩側的兩個空間。

既然你試圖要匹配,你應該在字符串的堅持到底的標誌$,像這樣

還有什麼是^[0-9][0-9]*點,當你可以使用^[0-9]+

^([0-9]{1,3}(?:,\d{3})*|[0-9]+)$ 

^(\d{1,3}(?:,\d{3})*|\d+)$ 

說明:

^     # Anchors to the beginning to the string. 
(     # Opens CG1 
    \d{1,3}   # Token: \d (digit) 
    (?:    # Opens NCG 
     ,    # Literal , 
     \d{3}   # Token: \d (digit) 
         # Repeats 3 times. 
    )*    # Closes NCG 
         # * repeats zero or more times 
|      # Alternation (CG1) 
    \d+    # Token: \d (digit) 
         # + repeats one or more times 
)      # Closes CG1 
$      # Anchors to the end to the string. 
+0

THX,對不起遲到了。它工作完美。 –

+0

很高興工作,謝謝。你也可以upvote答案:)。您可以隨心所欲地多選答案,當然,您只能接受答案爲「答案」。 @CodaChang –