ASP.NET RegularExpressionValidator Controls
Definition and Usage
RegularExpressionValidator controls are used to validate the input value matches the specified pattern.
Note: Unless your browser does not support client-side validation or EnableClientScript property is set to false, otherwise it will also perform server and client authentication.
Note: If theinput control is empty, validation will fail. Please use the RequiredFieldValidator control to make the field required (mandatory).
Attributes
属性 | 描述 |
---|---|
BackColor | RegularExpressionValidator 控件的背景颜色。 |
ControlToValidate | 要验证的控件的 id。 |
Display | 验证控件的显示行为。合法值有:
|
EnableClientScript | 布尔值,规定是否启用客户端验证。 |
Enabled | 布尔值,规定是否启用验证控件。 |
ErrorMessage | 当验证失败时,在 ValidationSummary 控件中显示的文本。 注释:如果未设置 Text 属性,文本也会显示在验证控件中。 |
ForeColor | 控件的前景颜色。 |
id | 控件的唯一 id。 |
IsValid | 布尔值,指示由 ControlToValidate 指定的控件是否通过验证。 |
runat | 规定该控件是一个服务器控件。必须设置为 "server"。 |
BackColor | RegularExpressionValidator 控件的背景颜色。 |
Text | 当验证失败时显示的消息。 |
ValidationExpression | 规定验证输入控件的正则表达式。在客户端和服务器上,表达式的语法是不同的。JScript 用于客户端。在服务器上,根据您规定的语言使用。 |
Examples
RegularExpressionValidator
In this example, we declare in an .aspx file a TextBox control, a Button control, a Label control, and a RegularExpressionValidator control. submit () function detects whether a page is valid. If so, then in the Label control returns "The page is valid!". If not, then in the Label control returns "The page is not valid!". If the validation fails, the text in the control RegularExpressionValidator "The zip code must be 5 numeric digits!".
Validation Server Controls