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 which is usallya achieved using  RegularExpressionValidator.

Here's how it works:

a) Set the ControlToValidate property to the ID of the TextBox.

b) Set the Operator property to DataTypeCheck.

c) Assign a ValidationDataType enumeration member to the Type property, which includes String, Integer, Double, Date, and Currency.

Advantage:

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, so i works better than RegularExpressionValidator when you have multilingual website.

blog comments powered by Disqus