• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

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
Asked:
VBdotnet2005
  • 2
  • 2
  • 2
1 Solution
 
käµfm³d 👽Commented:
Try:

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

Open in new window


...and if you require the leading $:

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

Open in new window

0
 
VBdotnet2005Author 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
 
käµfm³d 👽Commented:
Yes, you're correct...  I'm up way past my bedtime  : \

Corrected:

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

Open in new window


If the digits to the right of the decimal can be something other than zeros, then change the two zeros to "\d\d".
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Fernando SotoCommented:
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)$";

Open in new window

0
 
VBdotnet2005Author 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
 
Fernando SotoCommented:
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$

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now