This documentation is archived and is not being maintained.

RegularExpressionValidator Control

.NET Framework 1.1

The RegularExpressionValidator control validates that the values of another control match a specified expression.

In terms of validation, it behaves identically to the ASP.NET System.Web.UI.WebControls.RegularExpressionValidator control.

Mobile Controls Syntax

Required properties, defaults, and code-featured elements are noted in bold type.

<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>

Containment Rules

The following controls can contain a RegularExpressionValidator control.

Control Comments
System.Web.UI.MobileControls.Form Can contain any number of RegularExpressionValidator controls.
System.Web.UI.MobileControls.Panel Can contain any number of RegularExpressionValidator controls.

The RegularExpressionValidator control cannot contain any other controls.

Device Templates

None.

Device-Specific Behavior

When any validator is rendered, the device-specific nature of its rendering is exactly the same as the device-specific rendering of the Label control, except that the StyleReference property for the control is initially set to Error. When this happens, the control will use the error style in the page style sheet or, if none exists, it will use the system default style sheet.

Example

This example displays a text box for entering a ZIP code and uses a RegularExpressionValidator control to ensure that the value entered is a five-digit value by using the regular expression "^\d{5}$".

<%@ 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>

See Also

RegularExpressionValidator Class | RegularExpressionValidator Class Members| RegularExpressionValidator Control

Show: