Solved

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

Posted on 2011-03-08
4
383 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
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

785 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