asp.net 服务器端的验证控件

来源:互联网 发布:代申请淘宝达人大v 编辑:程序博客网 时间:2024/05/16 13:40

  对常用的几个服务器端的验证控件进行实验,在登陆页面常会用到。  

<table >
     <tr>
       <td>
         <asp:ValidationSummary ID="ErrorSummary" HeaderText ="用户操作常见错误信息。" runat ="server"   Font-Bold ="true"  ShowMessageBox="false"  ShowSummary ="true"  />
       </td>
     </tr>
      <tr>
        <td>
          用户名称:<asp:TextBox ID="UserName" runat="server" Width ="150"></asp:TextBox>
         <asp:RequiredFieldValidator ID="ru" runat="server" ErrorMessage="用户名称不能为空。Font-Bold =true 为加粗" ControlToValidate="UserName"  Display ="None"  ></asp:RequiredFieldValidator>
         <asp:RangeValidator ID="renge" runat ="server" ControlToValidate ="UserName" ErrorMessage ="必须是小写字母," MaximumValue ="z" MinimumValue ="a" Font-Bold ="true" Display ="None" ></asp:RangeValidator>
         </td></tr>
         <tr>
         <td>
          用户密码:<asp:TextBox ID="Password"  runat ="server" Width ="150"></asp:TextBox>
          <asp:RequiredFieldValidator ID="rp" runat ="server" ErrorMessage ="用户密码不能为空。" ControlToValidate ="Password" Display ="None"  ></asp:RequiredFieldValidator>
         </td></tr>
        
         <tr>
          <td>
          用户年龄:<asp:TextBox ID="UserAge" runat ="server" Width ="150"></asp:TextBox>
          <asp:RangeValidator ID="rangeAge" runat ="server" ControlToValidate ="UserAge" ErrorMessage ="您输入的数值必须再1~150之间的整数。" MaximumValue ="150" MinimumValue ="1" Type ="integer"  Font-Bold ="true" Display ="None" ></asp:RangeValidator>
          </td>
         </tr>
         <tr>
          <td>
          电子邮箱:<asp:TextBox ID="Email"  runat="server" Width ="150"></asp:TextBox>
          <asp:RegularExpressionValidator ID="regularExpreEmail" runat ="server" ErrorMessage ="电子邮箱的格式不正确。" ControlToValidate ="Email" Font-Bold ="true"  ValidationExpression ="/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*" Display ="None" ></asp:RegularExpressionValidator>
          </td>
         </tr>
         <tr>
          <td>
          电话号码:<asp:TextBox ID="Telephone" runat ="server" Width ="150"></asp:TextBox>
          <asp:RegularExpressionValidator ID="regulerExpreTelephone" runat ="server" ErrorMessage ="两种模式:一种是区号为3位,电话号码为8位,另一种是区号为4位,电话号码为7位。" ControlToValidate ="telephone" ValidationExpression ="/d{3}-/d{8}|/d{4}-/d{7}" Font-Bold ="true" Display ="None" ></asp:RegularExpressionValidator>
          </td>
         </tr>
         <tr>
          <td>
          移动电话:<asp:TextBox ID="MobilePhone" runat ="server" Width ="150" ></asp:TextBox>
          <asp:RegularExpressionValidator ID ="regularMobilphone" runat ="server" ErrorMessage ="只能是数字13*|15*,格式不正确" ControlToValidate ="MobilePhone" ValidationExpression ="13/d{9}|15/d{9}" Font-Bold ="true" Display ="None" ></asp:RegularExpressionValidator>        
          </td>
         </tr>
         <tr>
          <td>
          个人主页:<asp:TextBox ID ="httpMyself" runat ="server" Width ="150"></asp:TextBox>
          <asp:RegularExpressionValidator ID ="regularHttp" runat ="server" ErrorMessage ="输入正确的网址http://www.aaa.aaa.aa" ControlToValidate ="httpMyself" ValidationExpression ="http:///S+/./S+" Font-Bold ="true"  Display ="None" ></asp:RegularExpressionValidator>
          </td>
         </tr>
        
           <tr>
         <td align ="left">       
         <asp:Button ID="SureBtn" runat ="server" Text ="确定" Width ="80"/>        
         </td></tr>
    </table>