• Status: Solved
• Priority: Medium
• Security: Public
• Views: 396

# reg ex - \$ amount

I am looking a pattern to validate sample below
\$1.00
\$10.00
up to \$100,000.00

This pattern below is up to \$99.00
[0-9]?[0-9]\.[0-9][0-9]\$
0
VBdotnet2005
• 2
• 2
• 2
1 Solution

Commented:
Try:

``````^(100|\d\d),\d\d\d\.\d\d\$
``````

...and if you require the leading \$:

``````^\$(100|\d\d),\d\d\d\.\d\d\$
``````
0

Author Commented:
sorry, I need this format 1.00 up to 100,000.00
^(100|\d\d),\d\d\d\.\d\d\$
wont't work
0

Commented:
Yes, you're correct...  I'm up way past my bedtime  : \

Corrected:

``````^(?:100,000|(?:(?:(?:\d?\d,)?\d)?\d)?\d)\.00\$
``````

If the digits to the right of the decimal can be something other than zeros, then change the two zeros to "\d\d".
0

RetiredCommented:
Hi VBdotnet2005;

The following Regex pattern should give you what you need.

``````string pattern = @"^(?:[0-9]{1}\.[0-9]{2}|[0-9]{2}\.[0-9]{2}|[0-9]{3}\.[0-9]{2}|[0-9]{1},[0-9]{3}\.[0-9]{2}|[0-9]{2},[0-9]{3}\.[0-9]{2}|100,000\.00)\$";
``````
0

Author Commented:
I am so sorry guys. It does not need to be .00 at the end.  It can be 1.25 or 1.00.
Thank you very much in advance.
0

RetiredCommented:
Hi VBdotnet2005;

Just take @kaufmed solution and change the last two 00 to \d\d as shown below.

``````^(?:100,000|(?:(?:(?:\d?\d,)?\d)?\d)?\d)\.\d\d\$
``````
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.