jQuery.validation為什么我的一個輸入框不能實現驗證 用戶名-郵箱-手機號?是不是一次不能實現這么多驗證,需要自己編寫才可以?<!DOCTYPE html><html><head><meta charset="UTF-8"><title>練習</title><style type="text/css">.login {position: fixed;left: 37%;top: 10%;z-index: 200;background-color: #fff;width: 360px;margin: 0;padding: 0;border: 2px solid #C5C5D1;}.login_header h2 {border-bottom: 2px solid #C5C5D1;width:320px;margin:0 auto;color:#919292;height: 49px;line-height: 49px;}.login_header span {float: left;width: 80px;cursor: pointer;}.login_header span:hover {color: #018EFD;border-bottom: 2px solid #018EFD;}.cl_js {color: #018EFD;border-bottom: 2px solid #018EFD;}.login_close { position: absolute; top: 12px; right: 20px; width: 17px; height: 17px; background-color:#fff;?background-image:url(../images/close-1.png); background-repeat:no-repeat; outline: none;}.login_close:hover { position: absolute; top: 9px; right: 17px; width: 23px; height: 23px; background-color:#fff;?background-image:url(../images/close-m.png); background-repeat:no-repeat; outline: none;}.login_body {width: 300px;margin: 0 auto;}.login_body #login_p1 {font-size: 12px;text-align: left;color: red;width: 300px;height: 30px;line-height: 30px;}.login_body p {font-size: 12px;text-align: left;color: red;width: 300px;height: 20px;line-height: 20px;clear: both;}.login_in {width: 279px;height: 20px;line-height: 20px;padding: 9px 9px 9px 10px;outline: none;border: 1px solid #C5C5D1;}.login_yn {width: 120px;height: 20px;line-height: 20px;padding: 9px;outline: none;border: 1px solid #C5C5D1;float: left;}.login_ch {float: left;font-size: 13px;width: 107px;height: 14px;line-height: 14px; margin-bottom: 20px;}.login_w {float: right;font-size: 13px;}.login_s {width: 300px;height: 50px;font-size: 25px;background-color: #7DBDEF;color: #fff;outline: none;cursor: pointer;}.login_foot {width: 300px;height: 25px;line-height:25px;margin: 26px 30px 34px 30px;}.login_foot span { float: left; font: 14px "微軟雅黑"; margin-top: 3px; color: #7E7F7F; }.login_foot a {float: right;margin: 0 8px;}.register {display: none;}</style><script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script><script src="jquery-validation-1.15.0/dist/jquery.validate.js"></script><script>$(document).ready(function() {? ? validator=$("#login_f").validate({? ? ? ? debug:true,? ? ? ? rules:{? ? ? ? ? ? //? ? ? ? ? ? //? ? ? ? ? ? //這里怎么實現 ?用戶名-郵箱-手機號 同時驗證? ? ? ? ? ? //? ? ? ? ? ? //? ? ? ? ? ? login_username:{? ? ? ? ? ? ? ? remote:"../js/remote.json",? ? ? ? ? ? ? ? required:true,? ? ? ? ? ? ? ? isMobile:true,? ? ? ? ? ? ? ? //email:true,? ? ? ? ? ? },? ? ? ? ? ? login_password:{? ? ? ? ? ? ? ? required:true,? ? ? ? ? ? ? ? minlength:6,? ? ? ? ? ? ? ? maxlength:16,? ? ? ? ? ? },? ? ? ? ? ? login_va:{? ? ? ? ? ? ? ? isMobile:true,? ? ? ? ? ? }? ? ? ? },? ? ? ? messages:{? ? ? ? ? ? login_username:{? ? ? ? ? ? ? ? remote:"用戶不存在",? ? ? ? ? ? ? ? required:"必須填寫用戶名",? ? ? ? ? ? ? ? email:"請輸入正確的郵箱",? ? ? ? ? ? },? ? ? ? ? ? login_password:{? ? ? ? ? ? ? ? required:"必須填寫密碼",? ? ? ? ? ? ? ? minlength:"密碼最小為6位",? ? ? ? ? ? ? ? maxlength:"密碼最大為16位",? ? ? ? ? ? },? ? ? ? },? ? ? ? errorElement:"p",? ? });? ? //? ? //? ? //這里的判斷,當mobile=/^[0-9]$/時,手機號可以通過? ? // ? ? ? ? ? ?當mobile==/^[0-9]$/時,郵箱可以通過? ? //? ? //?$.validator.addMethod("isMobile", function(value, element) { ?? ? var length = value.length;? ? var mobile="";? ? if(mobile=/^[0-9]$/){? ? ? ? mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;? ? return this.optional(element) || (length == 11 && mobile.test(value));?? ? } else {? ? ? ? mobile=/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;? ? return this.optional(element) || (mobile.test(value)); ?? ? }?},"請輸入正確的郵箱或手機號");});</script></head><body><div>? ? ? <div></div>? ? ? <div>? ? ? ? <div>? ? ? ? ? ? <h2>? ? ? ? ? ? ? ? <span id="login_btn">登錄</span>? ? ? ? ? ? ? ? <span id="register_btn">注冊</span>? ? ? ? ? ? </h2>? ? ? ? ? ? <button type="button" id="close_btn" data-dismiss="modal" aria-hidden="true"></button>? ? ? ? </div>? ? ? ? <div >? ? ? ? ? ? <div>? ? ? ? ? ? ? ? <form id="login_f" action="">? ? ? ? ? ? ? ? ? ? <p id="login_p1"></p>? ? ? ? ? ? ? ? ? ? ? ? <input type="text" value="" placeholder="請輸入登錄郵箱/手機號" name="login_username" id="login_username">? ? ? ? ? ? ? ? ? ? <p></p>? ? ? ? ? ? ? ? ? ? ? ? <input type="password" value="" placeholder="6-16位密碼,區分大小寫,不能用空格" name="login_password">? ? ? ? ? ? ? ? ? ? <p></p>? ? ? ? ? ? ? ? ? ? ? ? <input type="text" value="" placeholder="請輸入驗證碼" name="login_va">? ? ? ? ? ? ? ? ? ? <p></p>? ? ? ? ? ? ? ? ? ? <label for="auto-signin">? ? ? ? ? ? ? ? ? ? ? ? <input type="checkbox" checked="checked" id="auto-signin">? ? ? ? ? ? ? ? ? ? ? ? 下次自動登錄? ? ? ? ? ? ? ? ? ? </label>? ? ? ? ? ? ? ? ? ? <a href="">忘記密碼</a>? ? ? ? ? ? ? ? ? ? <input type="submit" name="login" value="登錄">? ? ? ? ? ? ? ? </form>? ? ? ? ? ? </div>? ? ? ? ? ? <div>? ? ? ? ? ? ? ? <form action="">? ? ? ? ? ? ? ? ? ? <p></p>? ? ? ? ? ? ? ? ? ? <input type="text" value="" placeholder="請輸入注冊郵箱/手機號" name="register_usename">? ? ? ? ? ? ? ? ? ? <p></p>? ? ? ? ? ? ? ? ? ? <input type="password" value="" placeholder="6-16位密碼,區分大小寫,不能用空格" name="register_password">? ? ? ? ? ? ? ? ? ? <p></p>? ? ? ? ? ? ? ? ? ? <input type="text" value="" placeholder="請輸入驗證碼" name="register_va">? ? ? ? ? ? ? ? ? ? <p></p>? ? ? ? ? ? ? ? ? ? <input type="submit" value="注冊">? ? ? ? ? ? ? ? </form>? ? ? ? ? ? </div>? ? ? ? </div>? ? ? ? <div>? ? ? ? ? ? <span>其它方式登錄</span>? ? ? ? ? ? <a href=""><img src="images/login_foot-r.png" alt=""></a>? ? ? ? ? ? <a href=""><img src="images/login_foot-x.png" alt=""></a>? ? ? ? ? ? <a href=""><img src="images/login_foot-w.png" alt=""></a>? ? ? ? ? ? <a href=""><img src="images/login_foot-QQ.png" alt=""></a>? ? ? ? </div>? ? ? </div>? ? </div></body></html>
添加回答
舉報
0/150
提交
取消