.NET Tip of The Day
Learn one new .NET trick every day
Быстрое пополнение счета телефона      Login or Join

A simple method to validate an integer, double, date, and currency values entered into a textbox on ASP.NET page

Normally the CompareValidator is used to check one value against another on ASP.NET page. However it also can be used to ensure user has entered data in a correct format.

Here's how it works:

  1. Set the ControlToValidate property to the ID of the TextBox.
  2. Set the Operator property to DataTypeCheck.
  3. Assign a ValidationDataType enumeration member to the Type property, which includes String, Integer, Double, Date, and Currency.

Note: this method is culturally sensitive. This means that if you change your browsers settings to en-UK, a date of 1-28-01 correctly fires the validator, while 28-1-01 is allowed through. This is because the date format is day-month-year in that region.

1/5/2008

Comments:

Hi,

Thank you for this TIP. Very simple and so useful.

Regards

Prakash

prakash Babu 3/9/2008 9:30:02 AM

Great tip! Another one to add to my "I wish I'd known this X days/weeks/months ago" list :)

Ian Oxley 3/27/2008 11:51:45 AM

Great...its working,,,so nice and simple yet powerful...
Thanks

Mehboob Ali 12/10/2009 9:30:46 AM

Name
URL
E-mail
Provide your e-mail address to receive notification about new comments.
Message
HTML tags are not supported.
Please add 3 and 1 and type the answer here:
RSS .NET Tip of The Day
Subscribe to receive one tip from the .NET Tips and Tricks Community per day.
Previous Tips of The Day
The best of the .NET Tips & Tricks Community.
.NET Practitioners .NET Tips & Tricks Community
Every .NET practitioner has a trick up in their sleeve. This is the place to share it with other .NET people.
Submit a Tip
Discovered a new trick? Share it with others.
My Tips
Manage tips you authored.