在验证方面,该控件的行为与 ASP.NET System.Web.UI.WebControls.RegularExpressionValidator 控件相同。
移动控件语法
必需的属性、默认值和具有代码特征的元素以粗体显示。
<mobile:RegularExpresssionValidator
runat="server"
id="id"
Font-Name="fontName"
Font-Size="{NotSet|Normal|Small|Large}"
Font-Bold="{NotSet|False|True}"
Font-Italic="{NotSet|False|True}"
ForeColor="foregroundColor"
BackColor="backgroundColor"
Alignment="{NotSet|Left|Center|Right}"
StyleReference="styleReference"
Wrapping="{NotSet|Wrap|NoWrap}"
ControlToValidate="IdOfTargetControl"
Display="{None|Static|Dynamic}"
ErrorMessage="ErrorTextForSummary"
ValidationExpression="regexp"
>
text
</mobile:RegularExpressionValidator>
包容规则
以下控件可以包含 RegularExpressionValidator 控件。
控件 说明
System.Web.UI.MobileControls.Form 可以包含任意多个 RegularExpressionValidator 控件。
System.Web.UI.MobileControls.Panel 可以包含任意多个 RegularExpressionValidator 控件。
RegularExpressionValidator 控件不能包含任何其他控件。
设备模板
无。
特定于设备的行为
当呈现任何验证程序时,其特定于设备的呈现特性与 Label 控件的特定于设备的呈现特性完全相同,但该控件的 StyleReference 属性最初设置为 Error。当这种情况发生时,控件将使用页样式表中的错误样式,如果没有,则使用系统默认样式表。
示例
此示例显示一个用于输入邮政编码的文本框,并使用 RegularExpressionValidator 控件通过使用正则表达式 "^\d{5}$" 确保输入的值是一个 5 位值。
[Visual Basic]
<%@ Page Inherits=
"System.Web.UI.MobileControls.MobilePage" Language="VB" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<script language="vb" runat="server">
Protected Sub Submit_Click(sender As Object, e As EventArgs)
If Page.IsValid Then
ActiveForm = Form2
End If
End Sub
</script>
<mobile:Form id="Form1" runat="server">
<mobile:Label runat="server">
Please enter a ZIP code
</mobile:Label>
<mobile:TextBox id="zip" runat="server"/>
<mobile:RegularExpressionValidator ControlToValidate="zip"
ValidationExpression="^\d{5}$"
runat="server">
Invalid ZIP code
</mobile:RegularExpressionValidator>
<mobile:Command runat="server" OnClick="Submit_Click">
Submit
</mobile:Command>
</mobile:Form>
<mobile:Form id="Form2" runat="server">
<mobile:Label runat="server">ZIP code is submitted</mobile:Label>
</mobile:Form>
[C#]
<%@ Page Inherits=
"System.Web.UI.MobileControls.MobilePage" Language="C#" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<script language="c#" runat="server">
protected void Submit_Click(Object sender, EventArgs e)
{
if (Page.IsValid)
{
ActiveForm = Form2;
}
}
</script>
<mobile:Form id="Form1" runat="server">
<mobile:Label runat="server">
Please enter a ZIP code
</mobile:Label>
<mobile:TextBox id="zip" runat="server"/>
<mobile:RegularExpressionValidator ControlToValidate="zip"
ValidationExpression="^\d{5}$"
runat="server">
Invalid ZIP code
</mobile:RegularExpressionValidator>
<mobile:Command runat="server" OnClick="Submit_Click">
Submit
</mobile:Command>
</mobile:Form>
<mobile:Form id="Form2" runat="server">
<mobile:Label runat="server">ZIP code is submitted</mobile:Label>
</mobile:Form>







