jQuery:validate to add custom validation jQuery.validator.addMethod adds custom validation rules addMethod:name, method, message Simple example: adding a single verification Copy code The code is as follows: validate.js extended validation<br><script type="text/javascript" src="jquery.validate.js"><br>$("#tinyphp").validate({<br> // Add validation rules<br> rules: {<br> isZipCode: { //Verification Email<br> ><br><br> <br>validate.expand.js<br> <br><br><br><br> </div>Copy code<p></p> The code is as follows:<p></p> <div class="codetitle"><span>jQuery.validator.addMethod("isZipCode", function( value, element) { <a style="CURSOR: pointer" data="33106" class="copybut" id="copybut33106" onclick="doCopy('code33106')"> var tel = /^[0-9]{6}$/;<u> return this.optional(element) || (tel.test(value));</u>}, "Please fill in your zip code correctly");</a></span></div> <div class="codebody" id="code33106">Add multiple verification methods<br><br><br><br><br>Copy code</div> <p> The code is as follows:<br></p> <div class="codebody" id="code11079"> <br> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br><html xmlns="http://www.w3.org/1999/xhtml"><br><head><br><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br><title>validate.js拓展验证</title><br><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">邮编: 名字:<br>$("#tinyphp").validate({<br> // 添加验证规则<br> rules: {<br> isZipCode: { //验证邮箱<br> isZipCode: true<br> },<br> userName:{<br> required: true,<br> userName: true,<br> rangelength: [5,10] <br> }<br> },<br><br> //重设提示信息,可省略<br> messages:{<br> userName: {<br> required: "请填写用户名",<br> rangelength: "用户名必须在5-10个字符之间" <br> } <br><br> }<br>}); <br>