Definition and usage
The RegularExpressionValidator control is used to verify that the input values match the specified pattern.
Note: Both server side and client authentication are performed unless the browser does not support client authentication or the EnableClientScript property is set to False.
Note: If the input control is empty, validation will fail. Please use the RequiredFieldValidator control to make the field mandatory (required).
Property
Properties |
Description |
BackColor |
The background color of the RegularExpressionValidator control. |
ControlToValidate |
The ID of the control to validate. |
Display |
Validates the display behavior of the control. Valid values are:
- None-The control is not displayed. The error message is displayed only for the ValidationSummary control.
- Static-If validation fails, the control displays an error message. Even if the input passes validation, the space on the page to display the message is reserved, that is, the space used to display the message is pre-allocated.
- Dynamic-If validation fails, the control displays an error message. If the input is verified, the space on the page to display the message is not reserved, that is, the space used to display the message is dynamically added.
|
EnableClientScript |
Boolean value that specifies whether client-side validation is enabled. |
Enabled |
A Boolean value that specifies whether the validation control is enabled. |
ErrorMessage |
The text that is displayed in the ValidationSummary control when validation fails. Note: text is also displayed in the validation control if you do not set the Text property. |
ForeColor |
The foreground color of the control. |
Id |
The unique ID of the control. |
IsValid |
A Boolean value that indicates whether the control specified by ControlToValidate passes validation. |
Runat |
Specifies that the control is a server control. Must be set to "server". |
BackColor |
The background color of the RegularExpressionValidator control. |
Text |
The message that is displayed when validation fails. |
ValidationExpression |
Specifies the regular expression that validates the input control. On both the client and the server, the syntax of the expression is different. JScript is used for clients. On the server, in accordance with the language you specify. |
1<form id="Form1"runat="Server">2<div>3 4Input Character<asp:textbox id="TextBox1"runat="Server"></asp:TextBox>5<asp:regularexpressionvalidator id="RegularExpressionValidator1"runat="Server" 6Controltovalidate="TextBox1"Errormessage="4-6 characters"Forecolor="Red" 7validationexpression="\w{4,6}"></asp:RegularExpressionValidator>8<br/>9<asp:button id="BTN1"runat="Server"text="Submit"/>Ten One</div> A</form>
View Code
ASP. NET validation Control RegularExpressionValidator