jquery Plugin formvalidator Custom Function Extension Function example detailed _jquery

Source: Internet
Author: User
Tags lowercase

The example in this article describes the method of the jquery plug-in formvalidator custom function extension. Share to everyone for your reference, specific as follows:

jquery Formvalidator What is a form verification plug-in? Interested readers can refer to the jquery formvalidator form verification plug-in and other relevant documents of this site

Some text is omitted here.

The application of forms in the actual project is varied and the validation is changeable, but jquery Formvalidator provides us with a custom function interface, which is personally considered to be its main strength. Nonsense not much to say, direct instance.

Example: Landline and mobile phone, at least one choice, you can not choose.

Analysis: This belongs to the combination verification, which requires different verification conditions according to the different user selection frame.

Knowledge Point: Jquery Formvalidator provides a custom function interface for Functionvalidator ({fun:funname});

Landline phone

$ ("#txtMobileTel, #txtContactTel"). Formvalidator ({tipid: "Txtmobileteltip", OnShow: "Please fill in any one of the contact numbers", onfocus: " Please enter a mobile phone or landline telephone ", oncorrect:" Input correct!
"}). Functionvalidator ({fun:allempty}); Function Allempty (val, elem) {if ($ ("#txtMobileTel"). val () = "" && $ ("#txtContactTel"). val () = "") {return
 ' Please enter a mobile phone or landline '; else {if ($ ("#txtMobileTel"). Val ()!= "" && $ ("#txtContactTel"). Val ()!= "") {if ($ (#txtMobileTel). VA L ()). Search (/^ ((13[0-9]{1}) | ( 15[0-9]{1}) +\d{8})!=-1) {if (($ ("#txtContactTel"). Val ()). Search (/^ ([0\+]\d{2,3}-)? 0\d{2,3})? (\d{7,8})
    (-(\d{3,})) $/!=-1) {return true} else {return "landline phone format error";
   } else {return "mobile phone format error"; } else {if ($ ("#txtMobileTel"). Val ()!= "") {if (($ ("#txtMobileTel"). Val ()). Search (/^ ((13[0-9]{1) | (
    15[0-9]{1}) +\d{8})!=-1) {return true} else {return ' mobile phone format error '; } if ($ ("#txtContactTel"). Val ()!= "") {if (($ ("#txtContactTel"). Val ()). Search (/^ ([0\+]\d{2,3}-)? (0\d{2,3})? (\d{7,8})
    (-(\d{3,})) $/!=-1) {return true} else {return "landline phone format error";

 }
   }
  }
};

Example two: The regional Cascade Drop-down, when there is no two-level area of the Drop-down to cancel the check.

Provincial and Municipal regional cascade

$ ("#ddlOne"). Formvalidator ({onshow: "Please choose provinces and cities", onfocus: "Provinces and cities must choose", Oncorrect: "Input Correct"}). Inputvalidator ({min:1, onerror: " Please select a valid region "}). Functionvalidator ({fun:city});
 $ ("#ddlTwo"). Formvalidator ({onshow: "Please select City", onfocus: "City must Choose", Oncorrect: "Enter Correct"}). Inputvalidator ({min:1, onerror: " Please select a valid region "});
Function City (Val, elem) {
 var a = "";
 $.getjson (".. /customer/area.ashx?parentid= "+ $ (" #ddlOne option:selected "). Val (), NULL, function (JSON) { 
  if (Json[0].areacode = = "0") {
   $ ("#ddlTwo"). attr ("Disabled", true). Unformvalidator (true);//Unblock
  }
  else {
   $ ("#ddlTwo"). attr ("Disabled", false). Unformvalidator (false); Redo Check
  }}
 );


Common validation:

Integer:

Copy Code code as follows:
$ ("#zs"). Formvalidator ({onshow: "Please enter an integer", Oncorrect: "Thank you for your cooperation, your whole number is correct"}). Regexvalidator ({regexp: "Intege", DataType: " Enum ", OnError:" Incorrect integer Format "});

Positive integer:

Copy Code code as follows:

$ ("#zzs"). Formvalidator ({onshow: "Please enter a positive integer", Oncorrect: "Thank you for your cooperation, your positive integer is correct"}). Regexvalidator ({regexp: "Intege1", DataType: "Enum", OnError: "Incorrect integer Format"});

Negative integer:

Copy Code code as follows:

$ ("#fzs"). Formvalidator ({onshow: "Please enter a negative integer", Oncorrect: "Thank you for your cooperation, your negative integer is correct"}). Regexvalidator ({regexp: "Intege2", DataType: "Enum", OnError: "Negative integer format Incorrect"});

Positive:

Copy Code code as follows:

$ ("#zs1"). Formvalidator ({onshow: "Please enter a positive number", Oncorrect: "Thank you for your cooperation, your positive number is correct"}). Regexvalidator ({regexp: "NUM1", DataType: " Enum ", OnError:" Positive format Incorrect "});

Digital:

Copy Code code as follows:

$ ("#sz"). Formvalidator ({onshow: "Please enter a number", Oncorrect: "Thank you for your cooperation, your number is correct"}). Regexvalidator ({regexp: "num", datatype: "enum ", OnError:" Incorrect number format "});

Negative:

Copy Code code as follows:

$ ("#fs"). Formvalidator ({onshow: "Please enter negative numbers", Oncorrect: "Thank you for your cooperation, your negative numbers are correct"}). Regexvalidator ({regexp: "num2", DataType: " Enum ", onerror:" Negative format incorrect "});

Floating point numbers:

$ ("#zfds"). Formvalidator ({onshow: "Please enter a positive floating-point number", Oncorrect: "Thank you for your cooperation, your positive floating-point number is correct"}). Regexvalidator ({regexp: "Decmal1", DataType: "Enum", OnError: "Positive floating-point number format is incorrect"});
$ ("#ffds"). Formvalidator ({onshow: "Please enter negative floating-point number", Oncorrect: "Thank you for your cooperation, your negative floating-point number is correct"}). Regexvalidator ({regexp: "Decmal2", DataType: "Enum", OnError: "Negative floating-point number format is not correct"};
$ ("#fffds"). Formvalidator ({onshow: "Please enter a non-negative floating-point number", Oncorrect: "Thank you for your cooperation, your nonnegative floating-point number is correct"}). Regexvalidator ({regexp: "Decmal4", DataType: "Enum", OnError: "nonnegative floating-point number format incorrect"});
$ ("#fzfds"). Formvalidator ({onshow: "Please enter a non-positive floating-point number", Oncorrect: "Thank you for your cooperation, your non-positive floating-point number is correct"}). Regexvalidator ({regexp: "DECMAL5", DataType: "Enum", OnError: "Non-positive floating-point number format is incorrect"});

Cell phone:

Copy Code code as follows:

$ ("#sj"). Formvalidator ({onshow: "Please enter your mobile number", onfocus: "must be 13 or 15 to the beginning of Oh", Oncorrect: "Thank you for your cooperation, your mobile phone number is correct"}). Regexvalidator ( {regexp: "mobile", DataType: "Enum", OnError: "Cell phone number format is not correct"});

Landline:

Copy Code code as follows:

$ ("#dh"). Formvalidator ({onshow: "Please enter domestic telephone", onfocus: "For example: 0577-88888888 or omit area code 88888888", Oncorrect: "Thank you for your cooperation, your domestic telephone is correct"}) . Regexvalidator ({regexp: "tel", DataType: "Enum", OnError: "Domestic telephone format is not correct"});

Mailbox:

Copy Code code as follows:

$ ("#email"). Formvalidator ({onshow: "Please enter your email", onfocus: "Please note the email format you entered, for example: wzmaodong@126.com", Oncorrect: "Thank you for your cooperation. , your email is correct "}). Regexvalidator ({regexp:" email ", DataType:" Enum ", OnError:" Incorrect email format "});

Zip:

Copy Code code as follows:

$ ("#yb"). Formvalidator ({onshow: "Please enter ZIP code", onfocus: "6-digit number of Oh", Oncorrect: "Thank you for your cooperation, your postcode is correct"}). Regexvalidator ({regexp: " ZipCode ", datatype:" Enum ", OnError:" Postcode format is incorrect "});

Qq:

Copy Code code as follows:

$ ("#qq"). Formvalidator ({onshow: "Please enter QQ number", Oncorrect: "Thank you for your cooperation, your QQ number is correct"}). Regexvalidator ({regexp: "QQ", DataType: " Enum ", OnError:" QQ number format is not correct "});

Id:

Copy Code code as follows:

$ ("#sfz"). Formvalidator ({onshow: "Please enter your ID card", oncorrect: "Thank you for your cooperation, your ID card is correct"}). Regexvalidator ({regexp: "Idcard", datatype : "Enum", OnError: "Incorrect ID card format"});

Letters:

Copy Code code as follows:

$ ("#zm"). Formvalidator ({onshow: "Please enter the letter", Oncorrect: "Thank you for your cooperation, your letters are correct"}). Regexvalidator ({regexp: "letter", DataType: " Enum ", OnError:" Incorrect Letter Format "});

Capital:

Copy Code code as follows:

$ ("#dxzm"). Formvalidator ({onshow: "Please enter a capital letter", Oncorrect: "Thank you for your cooperation, your capital letter is correct"}). Regexvalidator ({regexp: "Letter_u", DataType: "Enum", OnError: "Uppercase format Incorrect"});

Lowercase letters:

Copy Code code as follows:

$ ("#xxzm"). Formvalidator ({onshow: "Please enter a lowercase letter", Oncorrect: "Thank you for your cooperation, your lowercase letter is correct"}). Regexvalidator ({regexp: "letter_l", DataType: "Enum", onerror: "Lowercase letter format not correct"});

I hope this article will help you with your jquery programming.

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.