Original address: http://www.cnblogs.com/talk/archive/2012/01/29/2330887.html
$ (function () {try {$.formvalidator.initconfig ({formid: "formtable", Errorfocus:false, Submitonce:true, Tipstyle: "Both", onerror:function () {//Verify obsolete callback function Alert ("The red hint is illegal, please modify it as prompted!") "); } }); Verify string (required) $ ("#name"). Formvalidator ({//verify: module name onshow: "(required)", onfocus: "(required) no more than 50 characters", Oncorrect: "(Correct)"}). Inputvalidator ({min:1, max:50, Onerrormin: "(Error) not Can be empty ", Onerrormax:" (Error) no more than 50 characters, Chinese characters counted two characters "}); Verify string (optional) $ ("#name"). Formvalidator ({//verify: module name onshow: "(optional)", onfocus: "(optional) no more than 50 characters", Oncorrect: "(correct)", empty:true}). inputvalidator ({min:1, max:50, Onerrormin: "(Error) cannot be empty", Onerrormax: "(Error) no more than 50 characters, Chinese characters count two characters"}); Verify Time $ ("#addDate"). Formvalidator ({ Verify: Send Time OnShow: "(required)", onfocus: "(required) Please select operation Time", Oncorrect: "(Correct)"}). Functionv Alidator ({fun:function (val, elem) {if (!/^\d{4}-\d{2}-\d{2}[]\d{2}:\d{2}$/.test (val)) { Return "(Error) Please select operation Time"; } return true; } }); Ajax Authentication $ ("#account"). Formvalidator ({//verify: module name onshow: "(required)", onfocus: "(required) no more than 50 characters", Oncorrect: "(Correct)"}). Inputvalidator ({min:1, max:50, Onerrormin: "(Error) not Can be empty ", Onerrormax:" (Error) no more than 50 characters, Chinese characters count two characters "}). Ajaxvalidator ({type:" post ", url:" En Terprisemanage!ajaxvalidatoruseraccount.action ", success:function (data) {if (data = =" 0 ") { return true; } else if (data = = "1") {return false; }}, OnError: "The account is already occupied, please replace it!" " }); Password and repeat password verification $ ("#password"). Formvalidator ({//verify: module name onshow: "(required)", onfocus: "(required) no more than 11 characters" , Oncorrect: "(Correct)"}). Inputvalidator ({min:1, max:50, Onerrormin: "( Error) cannot be null ", Onerrormax:" (Error) no more than 11 characters, Chinese characters counted two characters "}); $ ("#passwordRepeat"). Formvalidator ({onshow: "(required)", onfocus: "(required) 2 times password must be consistent", Oncorrect: "(Correct)"}). CompareValidator ({desid: "password", Operateor: "=", OnError: "(Error) 2 times password Inconsistent, please confirm "}"); Picture format Verification $ ("#tcCodeLogo"). Formvalidator ({onshow: "(optional)", onfocus: "(optional) please upload image file", Oncorrect: "(correct)", empty:true}). regexvalidator ({regexp:regexEnum.picture, oner ROR: "Only upload image File"}); Value validation $ ("#nameNum"). Formvalidator ({//verify: module name onshow: "(required)", ONFOCUS: "(required) value 1 to", Oncorrect: "(Correct)"}). Inputvalidator ({min:1, max:50, Type: "Value", Onerrormin: "(error) cannot be null", Onerrormax: "(Error) value 1 to 50"}); Phone Verification $ ("#linkPhone"). Formvalidator ({onshow: "(optional)", onfocus: "(optional)", Oncorrect: "(correct)", empty:true}). Regexvalidator ({regexp: "^ (\\d{3,4}-?\\d{7,8}| ( 13|15|18) \\d{9}) $ ", OnError:" (Error) Phone number format is incorrect, please check "}); Email Authentication $ ("#linkEmail"). Formvalidator ({onshow: "(optional)", onfocus: "(optional) Please select the correct email format", Oncorrect: "(correct)", empty:true}). regexvalidator ({regexp:regexEnum.email, O Nerror: "(Error) email format is not correct, please check"}); Select to verify $ ("#testSelect"). Formvalidator ({onshow: "(required)", onfocus: "(required) Select Options", Oncorrect: "(Correct)"}). Inputvalidator ({min: 0,//Start index onerror: "Did you forget to choose a degree!" }); When hidden, the default authentication is through $ ("#smsProductName"). Formvalidator ({//verify OnShow: "(required)", onfocus: "(required) no more than 50 characters Character, two characters ", Oncorrect:" (Correct) "}). Functionvalidator ({fun:function (val, elem) { if ($ ("#smsProductName"). Is (": hidden")) {return true; if (!/^\s{1,50}$/.test (val)) {return "(Error) no more than 50 characters, Chinese characters counted two characters"; } return true; } }); The multi-select selection box is slightly more complex to verify (": Checkbox[name= ' ProductType ']"). Formvalidator ({onshow: "(select at least one)", on Focus: "(select at least one)", Oncorrect: "(Correct)"}). Functionvalidator ({fun:function (val, elem) { var Objs = $ (": Checkbox[name= ' ProductType ']"); for (var i = 0; i < objs.length; i++) {if ($ (objs[i]). attr ("checked") = = True) { $ (' #productTypeTip '). Removeclass (); $ (' #productTypeTip '). addclass ("onsuccess"); $ (' #productTypeTip '). html (); $ (' #productTypeTip '). HTML ("<nobr> correct </nobr>"); return true; }} $ (' #productTypeTip '). Removeclass (); $ (' #productTypeTip '). addclass ("OnError"); $ (' #productTypeTip '). html (); $ (' #productTypeTip '). HTML ("<nobr> (select at least one) </nobr>"); return false; } }); } catch (e) {alert (e); }});
Some verification examples of Formvalidator