This source code is written and maintained by an individual, not a company. It has been provided for free to the Microsoft .NET user community with the expectation that users will take whatever action necessary to get the code to operate according to their needs. This includes debugging and enhancements. The source code is provided "as is" and there are neither warrantees to the quality of the work nor any expressed or implied agreements that the programmer will release any updates. The programmer will release updates and provide any support at his own discretion.
This set of controls provide Rapid Application Development (RAD) features for automatically checking the specified validity of user inputs. These controls are available in the
They cover almost all the validation scenarios. A validation control enables us to validate an input and display an error message if necessary. It is very much like other server-side controls, with certain additional methods and properties. First, the server treats it as an invisible control. After the user has entered erroneous data, it becomes visible. It is a powerful, rapid application development feature; however, a developer needs to understand its behavior and the methods thoroughly before he or she can appreciate it. All the validation controls inherit from the base class
BaseValidator, which is part of the class library namespace.
System.Web.UI.WebControls.BaseValidator exposes a series of properties and methods that are common to all the validation controls.
Checks that the validated control contains a value. It cannot be empty. Can be used in conjunction with other validators on a control to trap empty values. Simply, we can use it to check if the input control has any value. The most important property in the
<asp:RequiredFieldValidator id="validTxtName runat="server"
errorMessage="Name must be entered" display="static">
Checks the value against a regular expression (pattern). Checks that the value in the control matches a specified regular expression. If the validated control is empty, no validation takes place. The most important property in the
runat="server" display="static" controlToValidate="txtH"
errorMessage="Hours must be 1-3 digits only"
Checks if the value is acceptable compared to a given value or compared to the content of another control. In other words, it checks that the value in the validated control matches the value in another control or a specific value. The data type and comparison operation can be specified. If the validated control is empty, no validation takes place. The most important properties in the
<asp:CompareValidator id="comvR" runat="server" display="static"
controlToValidate="txtR" errorMessage="Rate must be numeric"
Checks if the input control’s value is within a specified range. In other words, it checks that the value in the validated control is within the specified text or numeric range. If the validated control is empty, no validation takes place. The most important properties in the
<asp:RangeValidator id="ranvDependents" runat="server"
errorMessage="Must be from 0 to 10"
type="Integer" minimumValue=0 maximumValue=10>
Allows you to develop custom validation. Performs user-defined validation on an input control using a specified function (client-side, server-side, or both). If the validated control is empty, no validation takes place. The most important property in the
<asp:CustomValidator id="cusvDeptNum" runat="server"
errorMessage="Must be in multiples of 10" >
Examples In VBScript
Sub validateDeptNum(source As Object, s as ServerValidateEventArgs)
If (CInt(s.Value) Mod 10)=0 Then
function validateLength(oSrc, args)
args.IsValid = (args.Value.length >= 10);
Displays a summary of all current validation errors. In other words, reports a summary of all errors. The most important properties in the
<asp:ValidationSummary id="valSummary" runat="server"
headerText="Please correct the following errors"
display="static" showSummary= "True" />
OK, for more about the validator controls: firstname.lastname@example.org.