注册时候的验证
0,var validator = $("#regform").validate({这个里面的#regform是form表单里面的id
1,首先先要导入jq放到<head>里面,
2.每个<input>里面都有name ,还有Id,还要加上<label for="Enter_the_password_again"></label>
3,messages里面相对于的名字,对应上面的rules里面的名字
<!-- 导入JQ --> <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js"></script> <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script> <!-- 导入地区的js --> <script type="text/javascript" src="view/region.js"></script> <script type="text/javascript"> function home(){ window.location.href="view/login.jsp"; } $.validator.setDefaults({ submitHandler: function() { add_save(); } }); $().ready(function() { // 提交时验证表单 var validator = $("#regform").validate({ errorPlacement: function(error, element) { $( element ) .closest( "form" ) .find( "label[for='" + element.attr( "id" ) + "']" ) .append( error ); }, rules: { Password: { required:true, minlength:6, maxlength:20 }, Enter_the_password_again: { equalTo:"#Password" }, Phonenumber:{ digits:true, required: true, minlength:11, maxlength: 11 }, }, messages: { Password: { required: "密码不能为空", minlength: " 请输入6——20个字", maxlength: " 请输入6——20个字" }, Enter_the_password_again: { equalTo: "两次密码输入不一致" }, Phonenumber:{ digits:"只能输入数字", required: "请输入您的手机", minlength: "请输入正确的手机号码格式", maxlength: "请输入正确的手机号码格式" }, } }); $(".cancel").click(function() { validator.resetForm(); }); }); </script> </head> <body> <form method="post" id="regform"> <table align = "center" border="1" style="border-collapse: collapse;"> <tr> <td colspan="2">代理注册</td> </tr> <tr> <td>账号:</td> <td><input type="text" name="Account" id="Account"/> <label for="Account"></label> </td> </tr> <tr> <td>密码:</td> <td><input type="text" name="Password" id="Password"/> <label for="Password"></label> </td> </tr> <tr> <td>请再输入一次密码:</td> <td><input type="text" name="Enter_the_password_again" id="Enter_the_password_again" /> <label for="Enter_the_password_again"></label> </td> </tr> <tr> <td>常用手机号码:</td> <td><input type="text" name="Phonenumber" id="Phonenumber"/> <label for="Phonenumber"></label> </td> </tr> <tr> <td>真实姓名:</td> <td><input type="text" name="Realname" /></td> </tr> <tr> <td>身份证号码:</td> <td><input type="text" name="Idcardnumber" /></td> </tr> <tr> <td>代理地区:</td> <td> <select id="Province" name="Province"></select> <select id="City" name="City"></select> <select id="Area" name="Area"></select> <script type="text/javascript"> addressInit('Province', 'City', 'Area'); </script> </td> </tr> <tr> <td>公司名称:</td> <td><input type="text" name="Nameofcompany" /></td> </tr> <tr> <td>推荐人ID:</td> <td><input type="text" name="Referees" /></td> </tr> <tr> <td>代理头像:</td> <td><input type="text" name="Agencyhead" /></td> </tr> <tr> <td>代理法人照片(手持身份证):</td> <td><input type="text" name="Photoagencyasalegalperson" /></td> </tr>