How to: Add and Configure a CustomValidator Control
If the user leaves the targeted control blank, it passes the custom validation test. To force the user to enter a value, add a RequiredFieldValidator control as well. For details, see How to: Add and Configure a RequiredFieldValidator Control.
To validate with a CustomValidator control
Add a CustomValidator control to the form that contains the target control.
Set the ControlToValidate property to the ID of the control to validate.
Set the ErrorMessage property to a string to display if the target control fails validation.
If you enter a string into the Text property, the CustomValidator control displays that text when an error occurs. If the Text property is left empty, the CustomValidator control displays the string defined in the ErrorMessage property.
Switch to Design view, and then double-click the CustomValidator control.
Visual Studio opens the code editor with an empty validation method.
Create the handler. For details, see Introduction to the CustomValidator Control.
How to: Add and Configure a CompareValidator Control
How to: Add and Configure a RangeValidator Control
How to: Add and Configure a RegularExpressionValidator Control
How to: Add and Configure a RequiredFieldValidator Control
How to: Add and Configure a ValidationSummary Control
Testing Validity Programmatically for Web Server Controls