RegularExpressionValidator, classe
Donne au contrôle la capacité de vérifier si la valeur d'un autre contrôle correspond à une expression régulière fournie.
public class System.Web.UI.MobileControls.RegularExpressionValidator :
System.Web.UI.MobileControls.BaseValidator
Notes
Cette classe se comporte de la même façon que le contrôle ASP.NETSystem.Web.UI.WebControls.RegularExpressionValidator.
Par défaut, les contrôles Command d'un formulaire déclenchent les contrôles validateurs du formulaire afin d'effectuer la validation nécessaire lorsque le formulaire est envoyé au serveur. Pour désactiver la validation automatique, affectez la valeur false à la propriété CausesValidation des contrôles Command.
Exemple
L'exemple suivant vous montre comment ajouter des propriétés d'expression régulière, telles que ValidationExpression et Text, par programme pendant le chargement d'une page.
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage"
Language="VB" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<script runat="server" language="vb">
Sub Page_Load(sender As Object, e As EventArgs)
' Define validation expressions.
revUserName.ValidationExpression = "^[a-zA-Z](.{1,9})$"
revPhone.ValidationExpression = _
"((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}"
rfvUserName.Text = "User name is required"
revUserName.Text = "Must be between 2 to 10 characters long"
revPhone.Text = "Please provide a valid number: (425) 555-0187"
' ErrorMessages appear in ValidationSummary.
revUserName.ErrorMessage = "Incorrect UserName format. Name" + _
" can be 2 to 10 characters long"
rfvUserName.ErrorMessage = "User name required"
revPhone.ErrorMessage = "Please provide a valid number: (425) 555-0187"
End Sub
Sub OnCmdClick1(sender As Object, e As EventArgs)
If Page.IsValid Then
ActiveForm = Form2
End If
End Sub
</script>
<mobile:Form runat="server" id="Form1" >
<mobile:Label runat="server" id="lblHeading"
Text="Provide your name and number" StyleReference="title" />
<mobile:Label runat="server" id="lblUserName"
Text="User Name (req'd)" />
<mobile:Textbox runat="server" id="txtUserName"/>
<mobile:RequiredFieldValidator runat="server" id="rfvUserName"
ControlToValidate="txtUserName" />
<mobile:RegularExpressionValidator runat="server" id="revUserName"
ControlToValidate="txtUserName" />
<mobile:Label runat="server" id="lblPhone" Text="Phone" />
<mobile:Textbox runat="server" id="txtPhone"/>
<mobile:RegularExpressionValidator runat="server" id="revPhone"
ControlToValidate="txtPhone" />
<mobile:ValidationSummary FormToValidate="Form1"
HeaderText="Error Summary:"
runat="server" />
<mobile:Command runat="server" id="Command1" text="Submit"
OnClick="OnCmdClick1"/>
</mobile:Form>
<mobile:Form runat="server" id="Form2" >
<mobile:Label runat="server" Text="Thank You." />
</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 runat="server" language="c#">
void Page_Load(Object sender, EventArgs e)
{
// Define validation expressions.
revUserName.ValidationExpression = "^[a-zA-Z](.{1,9})$";
revPhone.ValidationExpression =
"((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}";
rfvUserName.Text = "User name is required";
revUserName.Text = "Must be between 2 to 10 characters long";
revPhone.Text = "Please provide a valid number: (425) 555-0187";
// ErrorMessages appear in ValidationSummary.
revUserName.ErrorMessage = "Incorrect UserName format. Name" +
" can be 2 to 10 characters long";
rfvUserName.ErrorMessage = "User name required";
revPhone.ErrorMessage = "Please provide a valid number: (425) 555-0187";
}
void OnCmdClick1(Object sender, EventArgs e)
{
if (Page.IsValid)
{
ActiveForm = Form2;
}
}
</script>
<mobile:Form runat="server" id="Form1" >
<mobile:Label runat="server" id="lblHeading"
Text="Provide your name and number" StyleReference="title" />
<mobile:Label runat="server" id="lblUserName"
Text="User Name (req'd)" />
<mobile:Textbox runat="server" id="txtUserName"/>
<mobile:RequiredFieldValidator runat="server" id="rfvUserName"
ControlToValidate="txtUserName" />
<mobile:RegularExpressionValidator runat="server" id="revUserName"
ControlToValidate="txtUserName" />
<mobile:Label runat="server" id="lblPhone" Text="Phone" />
<mobile:Textbox runat="server" id="txtPhone"/>
<mobile:RegularExpressionValidator runat="server" id="revPhone"
ControlToValidate="txtPhone" />
<mobile:ValidationSummary FormToValidate="Form1"
HeaderText="Error Summary:"
runat="server" />
<mobile:Command runat="server" id="Command1" text="Submit"
OnClick="OnCmdClick1"/>
</mobile:Form>
<mobile:Form runat="server" id="Form2" >
<mobile:Label runat="server" Text="Thank You." />
</mobile:Form>
Configuration requise
Espace de noms : System.Web.UI.MobileControls
Assembly : System.Web.Mobile
Voir aussi
RegularExpressionValidator, contrôle | BaseValidator, classe | CompareValidator, classe | CustomValidator, classe | RangeValidator, classe | RequiredFieldValidator, classe | ValidationSummary, classe