• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • 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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Fernando SotoRetiredCommented:
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 SotoRetiredCommented:
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
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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