ASP.Net/Validation by Function/Phone Number — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 11:50, 26 мая 2010

Enter a valid phone number in the form xxx-xxx-xxxx (VB.net)

<%@ Page Language="vb" %>
<html>
   <head>
      <title>Validators collection example</title>
      <script runat="server">
         Sub Page_Load()
            Dim Validator as BaseValidator
            For Each Validator in Validators
               Message.Text &= Validator.ID & " error message: "
               Message.Text &= Validator.ErrorMessage & "<br/>"
            Next     
         End Sub
      </script>
   </head>
<body>
   <form runat="server">
      Phone: <asp:textbox id="phone" runat="server"/>
      <asp:requiredfieldvalidator 
         id="rfvPhone"
         controltovalidate="phone"
         display="dynamic"
         errormessage="Required!"
         runat="server"/>
      <asp:regularexpressionvalidator 
         id="revPhone"
         controltovalidate="phone"
         display="dynamic"
         validationexpression="^[2-9]\d{2}-\d{3}-\d{4}$"
         errormessage="Enter a valid phone number in the form xxx-xxx-xxxx"
         runat="server"/>
      <br/>
      <asp:button id="submit" text="Submit" runat="server"/>
   </form>
   <br/>
   <asp:label id="Message" runat="server"/>
</body>
</html>



Validating a Phone Number with a RegularExpressionValidator Control (VB.net)

<%@ Page Language=VB Debug=true %>
<HTML>
<HEAD>
<TITLE>Validating a Phone Number with a RegularExpressionValidator Control</TITLE>
</HEAD>
<form runat="server">
<BR><BR>
Please enter your phone number:<BR>
<asp:textbox 
    id="txtPhoneNumber" 
    runat=server 
/>
<asp:regularexpressionvalidator 
    id="regZipCode"
    controltovalidate="txtPhoneNumber"
    validationexpression="\(\d{3}\) \d{3}\-\d{4}"
    display="Dynamic"
    font-name="Arial" 
    font-size="11"
    runat=server
>
    You must enter a phone number in the form of (999) 999-9999.
</asp:regularexpressionvalidator>
<BR><BR>
<asp:button 
    id="butOK"
    text="OK"
    type="Submit"
    runat="server"
/>
</form>
</BODY>
</HTML>