Jan 8, 2008

Using CompareValidator for just Data Validation

A simple method to validate an integer, double, date, or 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. (Data Validation)

Here's how it works:

  • Set the ControlToValidate property to the ID of the TextBox.
  • Set the Operator property to DataTypeCheck.
  • Assign a ValidationDataType enumeration member to the Type property, which includes either one of the following : String, Integer, Double, Date, and Currency.

kick it on DotNetKicks.com

No comments: