各元件說明
密碼驗證
Asp.Net:
1 |
<span id="lnum1" style="color: #606060;"> 1:</span> 密碼:<span style="color: #0000ff;"><</span><span style="color: #800000;">asp:TextBox</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="passwd"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">asp:TextBox</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:RegularExpressionValidator</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="passrg"</span> |
1 |
<span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> |
1 |
<span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">ErrorMessage</span><span style="color: #0000ff;">="至少6碼與英數"</span> |
1 |
<span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #ff0000;">ControlToValidate</span><span style="color: #0000ff;">="passwd"</span> |
1 |
<span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #ff0000;">ValidationExpression</span><span style="color: #0000ff;">="^.*(?=.{6,})(?=.*\d)(?=.*[a-zA-Z]).*$"</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">asp:RegularExpressionValidator</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum8" style="color: #606060;"> 8:</span> |
ValidationExpression 說明:
(?=.{10,}): 密碼長度 10 個以上,{10,20} 表示能輸入10至20個字元
(?=.*\d): 至少要有一個 0-9 的數字
(?=.*[a-z]): 至少要有一個小寫的英文字母 (a-z)
(?=.*[A-Z]): 至少要有一個大寫的英文字母 (A-Z)
(?=.*[a-zA-Z]):至少要有一個英文字母
(?!.*[^\x00-\xff]): 表示不允許輸入 ASCII 以外的字元.
(?!.*[^\x21-\x7e]):表示不允許特殊字元
(?=.*[@#$%^&+=]): 至少要有清單中的一個特殊符號 (@#$%^&+=)
信箱驗證:
Asp.Net:
1 |
<span id="lnum1" style="color: #606060;"> 1:</span> 帳號:<span style="color: #0000ff;"><</span><span style="color: #800000;">asp:TextBox</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="email"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">asp:TextBox</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:RegularExpressionValidator</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="email_chk"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> |
1 |
<span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #ff0000;">ErrorMessage</span><span style="color: #0000ff;">="非E-MAIL 格式"</span> |
1 |
<span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">ControlToValidate</span><span style="color: #0000ff;">="email"</span> |
1 |
<span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #ff0000;">ValidationExpression</span><span style="color: #0000ff;">="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">asp:RegularExpressionValidator</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum7" style="color: #606060;"> 7:</span> |
同密碼驗證 , 只是換了驗證條件
密碼確認:
Asp.Net:
1 |
<span id="lnum1" style="color: #606060;"> 1:</span> 密碼:<span style="color: #0000ff;"><</span><span style="color: #800000;">asp:TextBox</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="passwd"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">asp:TextBox</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum2" style="color: #606060;"> 2:</span> 確認密碼:<span style="color: #0000ff;"><</span><span style="color: #800000;">asp:TextBox</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="passwd_ck"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> <span style="color: #0000ff;">></</span><span style="color: #800000;">asp:TextBox</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:CompareValidator</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="CompareValidator1"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> |
1 |
<span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">ErrorMessage</span><span style="color: #0000ff;">="密碼不同"</span> |
1 |
<span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #ff0000;">ControlToCompare</span><span style="color: #0000ff;">="passwd"</span> |
1 |
<span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #ff0000;">ControlToValidate</span><span style="color: #0000ff;">="passwd_ck"</span> |
1 |
<span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">asp</span><span style="color: #ff0000;">:CompareValidator</span><span style="color: #0000ff;">></span> |
利用 CompareValidator 做二個輸入框的比對
空白驗證:
Asp.Net:
1 |
<span id="lnum1" style="color: #606060;"> 1:</span> 帳號:<span style="color: #0000ff;"><</span><span style="color: #800000;">asp:TextBox</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="email"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> <span style="color: #ff0000;">ValidationGroup</span><span style="color: #0000ff;">="ck_inst"</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></</span><span style="color: #800000;">asp:TextBox</span><span style="color: #0000ff;">></span>(e-mail) |
1 |
<span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:RequiredFieldValidator</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="email_empty"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> |
1 |
<span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #ff0000;">ErrorMessage</span><span style="color: #0000ff;">="不可空白"</span> |
1 |
<span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">ControlToValidate</span><span style="color: #0000ff;">="email"</span> |
1 |
<span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #ff0000;">Display</span><span style="color: #0000ff;">="Dynamic"</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">asp:RequiredFieldValidator</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum7" style="color: #606060;"> 7:</span> |
Button 是否引發驗證:
2011-11-26 補充
進行空白驗證時,若表單為多 button , 若不要每個button 都進行驗證, 須將要驗證的物件 group 起來
Asp.Net:
1 |
<span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:TextBox</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="user_pw"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> <span style="color: #ff0000;">CssClass</span><span style="color: #0000ff;">="login"</span> <span style="color: #ff0000;">TextMode</span><span style="color: #0000ff;">="Password"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">asp:TextBox</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum2" style="color: #606060;"> 2:</span> |
1 |
<span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:RequiredFieldValidator</span> |
1 |
<span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="user_pw_empty"</span> |
1 |
<span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> |
1 |
<span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #ff0000;">ControlToValidate</span><span style="color: #0000ff;">="user_pw"</span> |
1 |
<span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #ff0000;">Display</span><span style="color: #0000ff;">="Dynamic"</span> |
1 |
<span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #ff0000;">ErrorMessage</span><span style="color: #0000ff;">="密碼空白"</span> |
1 |
<span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #ff0000;">ForeColor</span><span style="color: #0000ff;">="Red"</span> |
1 |
<span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #ff0000;">Font-Names</span><span style="color: #0000ff;">="微軟正黑體"</span> |
1 |
<span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #ff0000;">ValidationGroup</span><span style="color: #0000ff;">="vg_login"</span> |
1 |
<span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">></</span><span style="color: #800000;">asp:RequiredFieldValidator</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><</span><span style="color: #800000;">br</span> <span style="color: #0000ff;">/></span> |
1 |
<span id="lnum13" style="color: #606060;"> 13:</span> |
1 |
<span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:Button</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="login_ibtn"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> <span style="color: #ff0000;">ValidationGroup</span><span style="color: #0000ff;">="vg_login"</span> <span style="color: #0000ff;">/></span> |
1 |
<span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:Button</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="reg_ibtn"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> <span style="color: #ff0000;">CausesValidation</span><span style="color: #0000ff;">="False"</span> <span style="color: #ff0000;">PostBackUrl</span><span style="color: #0000ff;">="~/register/reg.aspx"</span> <span style="color: #0000ff;">/></span> |
(Visited 22 times, 1 visits today)