RegularExpressionValidator
RegularExpressionValidator Example
| Enter a 5-digit ZIP Code | ||
| Personal Information | ||
| Zip Code: | ||
@inherits ControlComponent
<table cellpadding="10" style="background-color:#eeeeee;">
<tr valign="top">
<td colspan="3">
<asp.Label @ref="this.output"
Text="Enter a 5-digit ZIP Code" />
</td>
</tr>
<tr>
<td colspan="3">
<b>Personal Information</b>
</td>
</tr>
<tr>
<td align="right">
Zip Code:
</td>
<td>
<asp.TextBox ID="TextBox1" />
</td>
<td>
<asp.RegularExpressionValidator ControlToValidate="TextBox1"
ValidationExpression="\d{5}"
Display="ValidatorDisplay.Static"
ErrorMessage="ZIP code must be 5 numeric digits"
EnableClientScript="false" />
</td>
</tr>
<tr>
<td></td>
<td colspan="2">
<asp.Button Text="Validate"
OnClick="this.ValidateBtn_Click" />
</td>
</tr>
</table>
@code {
private Label output;
protected void ValidateBtn_Click(object sender, EventArgs e)
{
if (this.Page.IsValid)
{
output.Text = "Page is Valid.";
}
else
{
output.Text = "Page is InValid.";
}
}
}
RegularExpressionValidator Metadata
| Name | Type | Kind |
|---|---|---|
| AccessKey | String | Parameter |
| Attributes | IReadOnlyDictionary | Parameter |
| BackColor | String | Parameter |
| BorderColor | String | Parameter |
| BorderStyle | BorderStyle | Parameter |
| BorderWidth | String | Parameter |
| ClientIDMode | ClientIDMode | Parameter |
| ControlToValidate | String | Parameter |
| CssClass | String | Parameter |
| Display | ValidatorDisplay | Parameter |
| EnableClientScript | Boolean | Parameter |
| Enabled | Boolean | Parameter |
| ErrorMessage | String | Parameter |
| FontBold | Boolean | Parameter |
| FontItalic | Boolean | Parameter |
| FontNames | String | Parameter |
| FontOverline | Boolean | Parameter |
| FontSize | String | Parameter |
| FontStrikeout | Boolean | Parameter |
| FontUnderline | Boolean | Parameter |
| ForeColor | String | Parameter |
| Height | String | Parameter |
| ID | String | Parameter |
| MatchTimeout | Nullable | Parameter |
| SetFocusOnError | Boolean | Parameter |
| Style | String | Parameter |
| TabIndex | Int16 | Parameter |
| Text | String | Parameter |
| ToolTip | String | Parameter |
| ValidationExpression | String | Parameter |
| ValidationGroup | String | Parameter |
| Visible | Boolean | Parameter |
| Width | String | Parameter |
| OnDataBinding | EventHandler | Event |
| OnDisposed | EventHandler | Event |
| OnInit | EventHandler | Event |
| OnLoad | EventHandler | Event |
| OnPreRender | EventHandler | Event |
| OnUnload | EventHandler | Event |