ValidForm Form Validation summary article _javascript tips

Source: Internet
Author: User

The recent project uses the form verification, chooses the validform_v5.3.2.

Let's take a look at some basic parameters:

Common form authentication methods:

Demo:

$ (". Demoform"). ValidForm ({//$ (". Demoform") indicates which form needs to be validated, 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 that you want to bind a point to to reset a form event under this form; Tiptype:1,//optional 1=>pop box,2=>side tip (parent.next.find with default pop), 3=>side tip (siblings; with default P
OP), 4=>side tip (siblings, none pop), default to 1, or pass in a function function, customize the display of the hint information (you can achieve any effect you want, specifically see demo page); ignorehidden:false,//Option True |
False defaults to False, when true: hidden form elements will not be validated; dragonfly:false,//Option True | False defaults to False, when true, without validation when the value is null; tipsweep:true,//option True |
False defaults to FALSE, which triggers detection only when the form is submitted, and the Blur event does not trigger detection (real-time validation is done in the background and does not show the detection results); Label: ". Label",//optional selector, find the prompt text to display when there is no binding nullmsg, and find by default.
Validform_label "under the words; showallerror:false,//Option True |
False,true: All error messages are displayed when the form is submitted, false: Stop detecting the element after the validation is not passed, and display only the error message for that element;
Postonce:true,//optional form can only be submitted once, true to open, do not fill the default shutdown;
Ajaxpost:true,///using AJAX to submit the form data, default false, the address is the action specified address;
datatype:{//incoming custom datatype type, either regular or 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) {//
The parameter gets is the form element value that is fetched, obj is the current form element, Curform is the currently validated form, REGXP is a built-in reference to some 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 to validate through, return string to indicate validation failure, string as error prompt, return false with ErrMsg or default error hint; 
"Phone": After the function () {//5.0 version, to achieve the verification effect of two, datatype name does not need to start with "Option_";
}, useplugin:{swfupload:{}, datepicker:{}, passwordstrength:{}, jqtransform:{selector: "Select,input"}},
Beforecheck:function (Curform) {//function that executes before the form is submitted for validation, the Curform parameter is the current form object. 
This will not continue to perform the validation operation if the return false is specified here;
}, Beforesubmit:function (curform) {//function executed before form submission, curform parameter is the current form object after validation succeeds. 
The form will not be submitted if you explicitly return false here; }, Callback:function (data) {///return is JSON format, {"Info": "Demo info", "status": "Y"}//info: output hint information;//status: Returns the status of the submitted data. Whether the commit was successful. If you can use "Y" to indicate a successful commit, "n" indicates that the commit failed, the ajax_post.php file returns data in the custom characters, mainly used in CALLBThe ACK function performs the corresponding callback operation according to the value; You can also get more information in the ajax_post.php file here, take the appropriate action, and//ajax the callback when encountering a server error, where data is {status:**, statustext:**, readystate:**,
responsetext:**};//Here performs the callback operation; Note: If the form is not submitted in AJAX mode, and the callback is passed in, then the data parameter is the current form object, the callback function executes after all the form validation is passed, and then determines whether the form is submitted, and the form is not committed if the callback is explicitly return false.
If return is true or not, the form is submitted.
}
}); Methods and properties of the ValidForm object: tipmsg: Customizing the hint information, by modifying this property value of the ValidForm object to make the different forms of the same page use different hint text; DataType: get some 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, skipping validation commits directly, and when sync is true, Ajax submissions are synchronized, and the form is submitted to this address when the URL address is passed in; abort (): Terminates the submission of Ajax; SubmitForm (Flag,url) : The form is submitted as set in the argument, and when flag is true, the form is submitted to this address when the validation is submitted directly, and the URL address is passed in; Resetform (): Resets the form; Resetstatus (): Resets the submit status of the form. When the Postonce parameter is passed in, the status is set to "posted" after the form has been successfully submitted, and the Reset commit state allows the form to continue to be submitted; GetStatus (): Gets the form's submission status, normal: Uncommitted, posting: submitting,
Posted: Has been successfully submitted; SetStatus (status): Set the submission status of the form, you can set the normal,posting,posted three states, without the parameter set state to posting, this state form can be validated, but cannot be submitted; Ignore (selector): Ignores validation of selected objects; Unignore (selector): Retrieves the validation effect of an object that is ignored by the Ignore method; addrule (rule): This side of the ValidForm object can bemethod to bind a form element to a validation rule; check (Bool,selector): Validates a specified object (the default validation of the current entire form), returns false by returning True (a bound object that is validated in real time, returns true if the format meets the requirements). Instead of waiting for the Ajax return result, the Boolean is true to verify that no prompts are displayed; config (Setup): This method allows you to modify initialization parameters, specify the submission address of the form, and set parameters for the form Ajax and real-time validated Ajax;

The following is a demo of the download address link, there is a need to download.

Demo Download Address

The above is a small set to introduce the ValidForm form verification Summary, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.