Solved

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

Posted on 2011-03-08
4
379 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
Comment Utility
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
Comment Utility
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 69

Expert Comment

by:Éric Moreau
Comment Utility
0
 

Author Closing Comment

by:TrialUser
Comment Utility
thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now