regex - ASP.NET Currency regular expression -


the currency required format looks

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

or integers 123456 or 2421323 , on.

i type below in validationexpression

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

but doesn't work.

do have ignore pattern whitespace on? if not, remove 2 spaces on each side of pipe.

since you're trying match either, should stick marker $ @ end of string, so

also point of ^[0-9][0-9]*, when can use ^[0-9]+?

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

or

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

explanation:

 ^                     # anchors beginning string.  (                     # opens cg1      \d{1,3}           # token: \d (digit)      (?:               # opens ncg          ,             # literal ,          \d{3}         # token: \d (digit)                          # repeats 3 times.      )*                # closes ncg                          # * repeats 0 or more times  |                     # alternation (cg1)      \d+               # token: \d (digit)                          # + repeats 1 or more times  )                     # closes cg1  $                     # anchors end string.