Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 404
  • Last Modified:

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

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
TrialUser
Asked:
TrialUser
  • 2
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
TrialUserAuthor Commented:
thanks
0

Featured Post

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.

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