📜  ASP.Net Web窗体RegularExpressionValidator

📅  最后修改于: 2020-12-28 00:39:12             🧑  作者: Mango

ASP.NET RegularExpressionValidator控件

该验证器用于根据正则表达式定义的模式来验证输入控件的值。

它使我们能够检查和验证可预测的字符序列,例如:电子邮件地址,电话号码等。

ValidationExpression属性用于指定正则表达式,该表达式用于验证输入控件。

正则表达式属性

Property Description
AccessKey It is used to set keyboard shortcut for the control.
BackColor It is used to set background color of the control.
BorderColor It is used to set border color of the control.
Font It is used to set font for the control text.
ForeColor It is used to set color of the control text.
Text It is used to set text to be shown for the control.
ToolTip It displays the text when mouse is over the control.
Visible To set visibility of control on the form.
Height It is used to set height of the control.
Width It is used to set width of the control.
ErrorMessage It is used to set error message that display when validation fails.
ControlToValidate It takes ID of control to validate.
ValidationExpression It is used to set regular expression to determine validity.

在这里,在下面的示例中,我们将说明如何使用RegularExpressionValidator控件根据给定的模式验证用户输入。

// RegularExpressionDemo.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RegularExpressionDemo.aspx.cs" 
Inherits="asp.netexample.RegularExpressionDemo" %>






Email ID

输出:

在浏览器中查看时,它将产生以下输出。

它将验证我们在正则表达式中指定的电子邮件格式。如果验证失败,则会引发错误消息。