Some verification examples of Formvalidator

Source: Internet
Author: User

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

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.