The method and tutorial of JQuery Validate verification

Source: Internet
Author: User

//verification of real name authentication$(function(){        //Chinese name VerificationJQuery.validator.addMethod ("Zh_verify",function(value, Element) {varTel =/^[\u4e00-\u9fa5\uf900-\ufa2d]{2,10}$/; return  This. Optional (Element) | |(Tel.test (value)); }, "Please input 2~10 words in Chinese!" "); //Identification Number VerificationJQuery.validator.addMethod ("Idcard_verify",function(value, Element) {varIdcard =/^ (\d{15}$|^\d{18}$|^\d{17} (\d| x|x)) $/; return  This. Optional (Element) | |(Idcard.test (value)); }, "Please enter the correct format of the ID number!" "); //Jquery.validate plug-in verification$ ("#nameauth"). Validate ({errorelement:' Div ', Errorclass:' Help-block ', Focusinvalid:false, ignore:"", rules: {tname: {required:true, Zh_verify:true}, Idcard: {required:true, Idcard_verify:true}, Con_idcard: {required:true, Equalto:'. Idcard '}}, messages: {tname: {required:"The real name can't be empty!" ", Rangelength:"Please input 2~18 Chinese!" "}, Idcard: {required:"ID can't be empty!" ", Rangelength:"Please enter a 15~18 character ID!" "}, Con_idcard: {required:"The confirmation number cannot be empty!" ", Equalto:' The confirmation number and the ID number are inconsistent! ‘}}, Errorlabelcontainer:"#resultMsg", Submithandler:function() {            //$ (form). Ajaxsubmit (); To submit a form synchronously            varTname = $ (' input[name=tname] '). Val (); varIdcard = $ (' input[name=idcard] '). Val (); varresultmsg = $ (' #resultMsg ');                    Ajaxsubmitform (Tname, Idcard, resultmsg); }    });})//Asynchronous execution MethodsfunctionAjaxsubmitform (Tname, Idcard, resultmsg) {$.ajax ({URL:"/member/nameauth", Data:"Tname=" + tname + "&idcard=" + Idcard + "&con_idcard=" +Idcard, type:"POST", Cache:false, DataType:"JSON", Success:function(data, textstatus) {if(Data.return) {window.location.reload (); }Else{resultmsg.css ({' Color ': ' Red '}. html (DATA.ERRMSG). Show (). Delay (0); }        }    });}
Or
$(function(){    //jquery.validate plug-in Custom Ajax authentication (verify that the account exists)$.validator.addmethod ("Checkuserexist",function(value,element) {varuser =value; $.ajax ({type:"POST", Async:true, DataType:' JSON ', URL:"/account/verifyaccount", Data:"Param=" + $ (' Input[name=newpassword] '). Val (), Success:function(response) {if(response) {res=response.state;        }            }        }); returnRes; },"The account does not exist, please check carefully!" "); //Jquery.validate plug-in verification$ ("#signupForm"). Validate ({rules: {newpassword : {required:true, rangelength:[6,30]}}, messages: {newpassword: {required:"Please enter the trading password of 6~30 characters!" ", Rangelength:"Please enter the trading password of 6~30 characters!" "}}, Submithandler:function(Form) {$ (form). Ajaxsubmit (); }    });})

JqueryValidate Tutorials

Http://www.w3cschool.cc/jquery/jquery-plugin-validate.html

The method and tutorial of JQuery Validate verification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.