Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Validation of currency amount enetred in a textbot in vb.net windows application

Posted on 2011-03-08
4
Medium Priority
?
397 Views
Last Modified: 2012-05-11
I have a textbox in Windows VB.net application in which the user enters a dollar amount. How can I make sure that it is a valid amount.  I am wondering that the user may enter  a decimal with comma, period or $ in it. So how can I validate that it iis a valid dollar amount. Any regex for this? Please help. Thanks
0
Comment
Question by:TrialUser
[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
4 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 35069457
You could use something like the following (note i'm only using a CultureInfo to force it to validate as US):
            string dollarAmount = "$123,456.99";

            System.Globalization.NumberStyles styles = System.Globalization.NumberStyles.AllowCurrencySymbol | System.Globalization.NumberStyles.AllowDecimalPoint | System.Globalization.NumberStyles.AllowThousands;
            decimal decAmount = decimal.Parse(dollarAmount, styles, new System.Globalization.CultureInfo("en-US"));

Open in new window

0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35069489
Or, in VB:
        Dim dollarAmount As String = "$123,456.99"

        Dim styles As System.Globalization.NumberStyles = Globalization.NumberStyles.AllowCurrencySymbol Or Globalization.NumberStyles.AllowDecimalPoint Or Globalization.NumberStyles.AllowThousands
        Dim decAmount As Decimal = Decimal.Parse(dollarAmount, styles, New System.Globalization.CultureInfo("en-US"))

Open in new window

0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 35069532
0
 

Author Closing Comment

by:TrialUser
ID: 35134899
thanks
0

Featured Post

Independent Software Vendors: 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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

705 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