一个完整的案例

类别:Asp 点击:0 评论:0 推荐:
我们现在要做一个杂志订阅系统,要用户输入Email,输入两次密码,密码要一样,密码要求安全,所以必须包括(!@#$%^&*+;:),输入用户的电话,最长20位,必须选择信用卡,输入卡号,卡号为15位,程序如下,好简单的,大家看看。



<%
 public sub OnSubmit(source as Object, e as EventArgs)
  if Page.IsValid then
   "数据入库等操作
  end if
 end sub
%>
<h3><font face="Verdana">订阅时尚生活杂志</font></h3>
<form runat=server>
 <hr width=600 size=1 noshade>
 <center>
 <asp:ValidationSummary ID="valSum" runat="server"
    HeaderText="您必须填写完整所有的选项"
    DisplayMode="SingleParagraph"
    Font-Name="verdana"
    Font-Size="12"
 />
 <p>



 <!-- sign-in -->
 <table border=0 width=600>
  <tr><td colspan=3>
  <table border=0 cellpadding=0 cellspacing=0 width="100%">
   <tr><td>
 <font face=geneva,arial size=-1><b>Sign-In Information</b>
 </font>
   </td></tr>
  </table>
  </td></tr>
    <tr>
    <td align=right>
     <font face=Arial size=2>输入您的Email</font>
               </td>
    <td>
   <asp:TextBox id=email width=200px maxlength=60 runat=server />
    </td>
    <td>
     <asp:RequiredFieldValidator id="emailReqVal"
        ControlToValidate="email"
        ErrorMessage="您的Email. "
        Display="Dynamic"
        Font-Name="Verdana" Font-Size="12"
        runat=server>
        *
     </asp:RequiredFieldValidator>
     <asp:RegularExpressionValidator id="emailRegexVal"
        ControlToValidate="email"
        Display="Static"
        ValidationExpression=
          "^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$"
        Font-Name="Arial" Font-Size="11"
        runat=server>
     不是一个正确的Email 请输入一个正确的Email
     </asp:RegularExpressionValidator>
    </td>
   </tr>
   <tr>
    <td align=right>
     <font face=Arial size=2>密码:</font>
    </td>
    <td>
     <asp:TextBox id=passwd TextMode="password" maxlength=20
            runat=server/>
    </td>
    <td>
     <asp:RequiredFieldValidator id="passwdReqVal"
        ControlToValidate="passwd"
        ErrorMessage="密码. "
        Display="Dynamic"
        Font-Name="Verdana" Font-Size="12"
        runat=server>
        *
     </asp:RequiredFieldValidator>
     <asp:RegularExpressionValidator id="passwdRegexBal"
        ControlToValidate="passwd"
        ValidationExpression=".*[!@#$%^&*+;:].*"
        Display="Static"
        Font-Name="Arial" Font-Size="11"
        Width="100%" runat=server>
     密码必须包括下面中的一个 (!@#$%^&*+;:)
     </asp:RegularExpressionValidator>
    </td>
   </tr>
   <tr>
    <td align=right>
     <font face=Arial size=2>请再输入一次密码:</font>
    </td>
    <td>
     <asp:TextBox id=passwd2 TextMode="password" maxlength=20
        runat=server/>
    </td>
    <td>
     <asp:RequiredFieldValidator id="passwd2ReqVal"
        ControlToValidate="passwd2"
        ErrorMessage="再输入一次密码. "
        Display="Dynamic"
        Font-Name="Verdana" Font-Size="12"
        runat=server>
        *
     </asp:RequiredFieldValidator>
     <asp:CompareValidator id="CompareValidator1"
      ControlToValidate="passwd2" ControlToCompare="passwd"
      Display="Static"
      Font-Name="Arial" Font-Size="11"
      runat=server>
      两次输入的密码怎么不一样:)
     </asp:CompareValidator>
    </td>
   </tr>
    <tr><td colspan=3> </td></tr>
    <!-- personalization information -->
    <tr><td colspan=3>
     <table border=0 cellpadding=0 cellspacing=0 width="100%">
      <tr><td><font face=geneva,arial size=-1>
       <b>Personal Information</b></font>
      </td></tr>
     </table>
    </td></tr>
   <tr>
    <td align=right>
     <font face=Arial size=2>电话:</font>
   </td>
   <td>
    <asp:TextBox id="phone" maxlength=20 runat="server" />
   </td>
   <td>
    <asp:RequiredFieldValidator id="phoneReqVal"
      ControlToValidate="phone"
      ErrorMessage="Phone. "
      Display="Dynamic"
      Font-Name="Verdana" Font-Size="12"
      runat=server>
      *
    </asp:RequiredFieldValidator>
   </td>
  </tr>
  <tr><td colspan=3> </td></tr>



   <!-- Credit Card Info -->
  <tr>
   <td colspan=3>
   <font face=Arial size=2><b>Credit Card Information</b></font>
   </td>
  </tr>
  <tr>
   <td align=right>
    <font face=Arial size=2>Card Type:</font>
   </td>
   <td>
    <ASP:RadioButtonList id=ccType
       Font-Name="Arial" RepeatLayout="Flow" runat=server>
    <asp:ListItem>招商银行一卡通</asp:ListItem>
    <asp:ListItem>建设银行龙卡</asp:ListItem>
    </ASP:RadioButtonList>
   </td>
   <td>
    <asp:RequiredFieldValidator id="ccTypeReqVal"
                                         ControlToValidate="ccType"
       ErrorMessage="信用卡种类. "
       Display="Static"
       InitialValue=""
       Font-Name="Verdana" Font-Size="12"
       runat=server>
        *
    </asp:RequiredFieldValidator>
   </td>
  </tr>
  <tr>
   <td align=right>
    <font face=Arial size=2>Card Number:</font>
   </td>
   <td>
    <ASP:TextBox id=ccNum runat=server />
   </td>
   <td>
    <asp:RequiredFieldValidator id="ccNumReqVal"
       ControlToValidate="ccNum"
       ErrorMessage="信用卡号. "
       Display="Dynamic"
       Font-Name="Verdana" Font-Size="12"
       runat=server>
       *
    </asp:RequiredFieldValidator>
    <asp:RegularExpressionValidator id="ccNumCustVal"
       ControlToValidate="ccNum"
       Display="Static"
       ValidationExpression="^\d{15}$"
       Font-Name="Arial" Font-Size="11"
       runat=server>
    信用卡号错误
    </asp:RegularExpressionValidator>
   </td>
  </tr>
 </table>
 <p>
 <input runat="server" type=submit value="注册">
 <p>
</form>
</center>



   好了,表单的验证,我们就讲到这里,下一讲,我们将介绍ASP.net处理数据的核心部分,数据绑定

本文地址:http://com.8s8s.com/it/it7951.htm