ValidForm Form Validation Summary

Source: Internet
Author: User

In recent projects, the validation of forms has been used, and validform_v5.3.2 has been selected.

Let's take a look at some basic parameters:

General form Validation methods:
Demo:

$ (". Demoform"). ValidForm ({//$ (". Demoform") indicates which form needs to be verified and the name should be added to the form form; Btnsubmit: "#btn_sub",//#btn_sub是该表单下要绑定点击提交表单事件的按钮; If the form contains a submit button, the parameter can be omitted; btnreset: ". Btn_reset",//optional. Btn_reset is the button under the form to bind a fixed-point click Reset Form Event; tiptype:1,//optional 1=>pop box,2 =>side tip (parent.next.find; with default pops), 3=>side tip (siblings; with default pop), 4=>side tip (siblings; None Pop), the default is 1, you can also pass in a function, customize the display of the prompt information (can achieve any effect you want, see the demo page); ignorehidden:false,//Optional True | False defaults to False when true: hidden form elements will not be validated; dragonfly:false,//selectable true | False defaults to False, and when True, the value is null without validation; tipsweep:true,//Optional True | False defaults to FALSE, which triggers detection only when the form commits, and the Blur event does not trigger detection (real-time validation is performed in the background, the test results are not displayed); Label: ". Label",//optional selector, to find the hint text to display when there is no binding nullmsg Default Find ". Validform_label "text under" showallerror:false,//Optional True | False,true: All error messages are displayed when the form is submitted, false: stops detection of subsequent elements when a validation fails, and only displays error messages for that element; postonce:true,//Can the option form be submitted only once, true on, Do not fill the default closed; Ajaxpost:true,//Use AJAX to submit form data, default false, the commit address is the action specified address; datatype:{//incoming custom datatype type, can be regular, It can also be a function (a parameter is passed in the function); *6-20 ":/^[^\s]{6,20}$/,"Z2-4":/^[\u4e00-\u9fa5\uf900-\ufa2d]{2,4}$/, "username": function (GETS,OBJ,CURFORM,REGXP) {//parameter gets is the form element value obtained, Obj is the current form element, Curform is the currently validated form, and REGXP is a reference to some of the built-in regular expressions; var reg1=/^[\w\. {4,16}$/,reg2=/^[\u4e00-\u9fa5\uf900-\ufa2d]{2,8}$/;if (Reg1.test (gets)) {return true;} if (Reg2.test (gets)) {return true;} Return false;//note Returns can return TRUE or false or string literals, true means that validation passed, the return string indicates that validation failed, the string is displayed as an error prompt, False is returned with ERRMSG or the default error prompt;}, "Phone    ": function () {///5.0 version, to achieve two of the verification effect, datatype name does not need to start with" Option_ "; }},useplugin:{swfupload:{},datepicker:{},passwordstrength:{},jqtransform:{selector: "Select,input"}}, Beforecheck:function (Curform) {//The function executed before the form submission performs validation, curform parameter is the current form object.    This will not proceed with the validation operation if the return is explicitly false. },beforesubmit:function (Curform) {//after validation succeeds, the function that the form executes before it is submitted, the Curform parameter is the current form object.    The form will not be submitted if it is explicitly return false; The},callback:function (data) {///return data is in JSON format {"Info": "Demo info", "status": "Y"}//info: output hint information;//status: Returns the status of the submitted data, Whether the submission was successful. If you can use "Y" to indicate the success of the Commit, "n" indicates that the commit failed, in the ajax_post.php file return data in the custom character, mainly used in the callback function according to the value of the corresponding callback operation;//You can also be in AJAX_POST.PThe HP file returns more information to be obtained here, for the appropriate operation;//ajax also executes a callback when it encounters a service-side error, when data is {status:**, statustext:**, readystate:**, responsetext:**};// The callback operation is performed here;//NOTE: If the form is not AJAX-submitted, the data parameter is the current form object, the callback function executes after the form is validated, and then determines whether to submit the form, and if callback explicitly return false, the callback The form is not committed, and if return is true or no return is present, the form is submitted. }}); ValidForm Object Methods and properties: Tipmsg: Custom prompt information, by modifying this property value of the ValidForm object to use different cue text for different forms on the same page; DataType: Get built-in regular; EQ (n) : Gets the nth element of the ValidForm object; Ajaxpost (Flag,sync,url): Submits the form in an AJAX manner. When flag is true, skip validation Direct commit, Sync is true when Ajax commits synchronously, when the URL address is passed in, the form is submitted to this address; abort (): Terminate Ajax commit; SubmitForm (Flag,url) : Submit the form as set in the parameter, flag is true, skip verification direct commit, when the URL address is passed in, the form will be submitted to this address; Resetform (): Reset form; Resetstatus (): Resets the form's submission status. If the Postonce parameter is passed in, the form will be set to "posted" after it is successfully submitted, and the commit status can be reset so that the form can continue to be submitted; GetStatus (): Get the form's submission status, normal: Uncommitted, posting: committing, Posted: Successfully submitted, SetStatus (status): Set the form's submission status, you can set normal,posting,posted three states, no parameters set the status to posting, the status form can be verified, but cannot be submitted ; Ignore (selector): Ignores validation of the selected object, Unignore (selector): Re-obtains the validation effect from the object that the Ignore method ignores; addRule (rule) : You can bind validation rules to form elements by this method of the ValidForm object, check (bool,selector): Validate the specified object (the current entire form is validated by default), passreturn true, otherwise false (bind real-time validation of the object, the format conforms to the requirements when the return of true, without waiting for the results of Ajax), BOOL is true when only the validation does not show the prompt message; Config: This method can be used to modify the initialization parameters. Specify the submission address of the form, set parameters for Ajax and real-time validation of the form in the Ajax;

ValidForm Form Validation summary

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.