Jquery VailDate初探
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>测试</title> 5 <script src="js/jquery-1.9.1.js" type="text/javascript"></script> 6 <script src="js/jquery.validate-vsdoc.js" type="text/javascript"></script> 7 <script type="text/javascript"> 8 $(function() { 9 $("#test1").validate({ 10 rules: { 11 txtLoginIdName: { 12 required: true, 13 maxlength: 10, 14 minlength: 5 15 }, 16 txtPwdName: { 17 required: true, 18 minlength: 2 19 }, 20 confirm_pwdName: { 21 required: true, 22 equalTo: "#txtPwd" 23 } 24 }, 25 messages: { 26 txtLoginIdName: "务必输入用户名", 27 txtPwdName: { 28 required: "务必输入密码", 29 minlengt: "最小长度为2", 30 maxlength: "最大长度10" 31 }, 32 confirm_pwd: { 33 equalTo: "两次输入务必一致" 34 } 35 } 36 }); 37 $.extend($.validator.messages, { 38 required: "必选字段", 39 remote: "请修正该字段", 40 email: "请输入正确格式的电子邮件", 41 url: "请输入合法的网址", 42 date: "请输入合法的日期", 43 dateISO: "请输入合法的日期 (ISO).", 44 number: "请输入合法的数字", 45 digits: "只能输入整数", 46 creditcard: "请输入合法的信用卡号", 47 equalTo: "请再次输入相同的值", 48 accept: "请输入拥有合法后缀名的字符串", 49 maxlength: $.validator.format("请输入一个长度最多是 {0} 的字符串"), 50 minlength: $.validator.format("请输入一个长度最少是 {0} 的字符串"), 51 rangelength: $.validator.format("请输入一个长度介于 {0} 和 {1} 之间的字符串"), 52 range: $.validator.format("请输入一个介于 {0} 和 {1} 之间的值"), 53 max: $.validator.format("请输入一个最大为 {0} 的值"), 54 min: $.validator.format("请输入一个最小为 {0} 的值") 55 }); 56 }); 57 </script> 58 </head> 59 <body> 60 <form id="test1" name="test1" method="POST" action=""> 61 <span>用户名:</span><input type="text" id="txtName" name="txtLoginIdName" class="required" /><br /> 62 <span>密 码:</span><input type="text" id="txtPwd" name="txtPwdName" /><br/> 63 <span>再次输入密码</span><input type="text" id="confirm_pwd" name="confirm_pwdName" /> 64 <input type="submit" value="提交" name="subText" id="subText" /> 65 </form> 66 </body> 67 </html>
小demo
vaildate是根据标签的name属性进行操作,