Solved

check money in regex

Posted on 2013-01-30
3
200 Views
Last Modified: 2013-02-14
I want to check if it is a good $ amount and txtpriceamount can not be blank.  It could also be a negative number.  txtpriceamount is required.

10.00 yes
1.00 yes
0.00 yes
0.02 yes
0.00 yes

-10.00 yes
-1.00 yes
-0.00 yes
-0.02 yes
-0.00 yes


1 no
text is no




 <asp:TextBox ID="txtpriceamount" runat="server"></asp:TextBox>
              &nbsp;<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
                    ControlToValidate="txtpriceamount" ErrorMessage="Incorrect Amount" ValidationExpression="^[1-9]+\d*\.\d{2}$"></asp:RegularExpressionValidator>
                &nbsp;
0
Comment
Question by:VBdotnet2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 250 total points
ID: 38837467
Are those the only numbers you want or you want to have any valid money value?

Here's one:
^-?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})$

Open in new window


All below will be valid. But it can be adjust to your requirement.

10.00
1.00
0.00
0.02
0.00
-10.00
-1.00
-0.00
-0.02
-0.00
100.00
1000.00
10,000.00
100,000.00

This  will not allow commas:
^-?([1-9]\d*|(\d+))(\.\d{2})$

Open in new window


FYI: Try tool like Expresso for creating/testing regexs..
0
 
LVL 29

Assisted Solution

by:Kumaraswamy R
Kumaraswamy R earned 250 total points
ID: 38838398
This worked too.
 
^\$?[0-9]+(,[0-9]{3})*(\.[0-9]{2})?$
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38840617
For the "txtpriceamount can not be blank.":

You simply add a RequireFieldValidator for the textbox in addition to your ReqFieldValidator.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question