<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="jquery-3.2.1.js"></script> <script src="jquery.validate.js"></script> <script type="text/javascript"> $(function () { $("#myForm").validate({ rules:{ uname:"required", pass:{ required:true, minlength:6, maxlength:12 }, upass:{ required:true, minlength:6, maxlength:12, equalTo:"#pass" }, uphone:{ required:true, minlength:7, maxlength:11, }, email:{ required:true, email:true }, ID:{ required:true, minlength:16, maxlength:18, } }, messages:{ uname:"用户名必填", pass:{ required:"密码必填", minlength:"密码长度在6-12之间", maxlength:"密码长度在6-12之间" }, upass:{ required:"密码必填", minlength:"密码长度在6-12之间", maxlength:"密码长度在6-12之间", equalTo:"两次密码不一样" }, uphone:{ required:"手机号必填", minlength:"手机长度在7-11之间", maxlength:"手机长度在7-11之间", }, email:{ required:"邮箱必填", email:"邮箱格式不正确" }, ID:{ required:"身份证必填", minlength:"身份证长度在16-18之间", maxlength:"身份证长度在16-18之间", } } }) }) </script> </head> <body> <form id="myForm" action="#"> 用户名:<input type="text" name=uname id="uname"><br> 密码:<input type="text" name=pass id="pass"><br> 确认密码:<input type="text" name=upass id="upass"><br> 手机号:<input type="text" name=uphone id="uphone"><br> 邮箱:<input type="text" name=email id="email"><br> 身份证:<input type="text" name=ID id="ID"><br> <input type="submit" value="提交"> </form> </body> </html>