Solved

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

Posted on 2011-03-08
4
386 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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