FormValidate form verification function code update and download

Source: Internet
Author: User

FormValidate feature update

Download:
Http://xiazai.jb51.net/jslib/FormValidate.rar

More common methods:

Http://jobj.googlecode.com/svn/trunk/FormValidate/demo.html

Add method:
Extend,
Add Verification Mode 4, the same as 3, but immediately stop the downward check when the verification fails. In Mode 3, if an error occurs, the error is recorded and checked downward. in Mode 4, the error is not checked downward.


Usage:


<Input type = "text" name = "name [0]" id = "name [0]" ruleTpl = "0"/>
<Input type = "text" name = "birthday [0]" id = "birthday [0]" ruleTpl = "1"/>
.....
.....
Var checkRule = [
{Name: "name [0]", required: true, min: 2, max: 3, msg: "enter a name! Length must be greater than 2, less than 3 "},
{Name: "birthday [0]", required: false, type: "Date", msg: "birthdate is optional. If you enter it, enter the correct Date "},
{Name: "email [0]", required: false, type: "Email", msg: "email is optional. If you enter it, enter the correct Email address "},
{Name: "scoreA [0]", required: true, type: "Num", min: 0, max: 100, msg: "Chinese score is required, must be greater than 0 and less than 100 "},
{Name: "scoreB [0]", required: true, type: "Num", min: 0, max: 100, msg: "The mathematical score is required, must be greater than 0 and less than 100 "},
{Name: "scoreC [0]", required: true, type: "Num", min: 0, max: 100, msg: "English score is required, must be greater than 0 and less than 100 "}
];

JObj. plugin ("FormValidate ");
Var va = JObj. Plugin. FormValidate;

Va. extend (document. forms [0], "ruleTpl", checkRule );
Return va. validate (document. forms [0], checkRule, 4 );

Explanation:
Why?
If you do not dynamically add form items, you can delete the va. extend sentence. But if you add a form item dynamically... The new form item cannot be specified.
In this way, it is the verification rule specified by ruleTpl. This ruleTpl can be any string (not its value). For example, if you replace ruleTpl with ttt, you must write it:
Va. extend (document. forms [0], 'ttt', checkRule)
RuleTpl exists as a custom attribute of a form item. Its value must be a subscript of checkRule. If this subscript is not saved, this item is not checked by default. Otherwise, the elements of the selected checkRule are copied to dynamically add verification rules.

When adding this function, I encountered several interesting questions. Let's talk about it below:

1. Address reference. Do not run it. Enter the value of variable a in the following code.

Var a = [{name: 1}];
Var tmp = a. push (a [a. length-1]);
A [tmp-1]. name = 2;
If you say a = [{name: 1}, {name: 2}], you are wrong. The actual value is:
A = [{name: 2}, {name: 2}];

The reason is very simple, because the push object is an object and the object is an address reference in JS, so a [tmp-1]. when name = 2, it actually changes the value of a [0.

The following section is very simple. The value reference won't happen above.


Var a = [1, 2, 3];
A. push (a [a. length-1]);
Alert ();
A [a. length-1] = 4;
Alert ();
2. dynamically Delete form items under FF.
If a form item is deleted dynamically without alert, form ['itemname'] is still the deleted form item.
At this time, its parentNode and form are all null, but they cannot be determined by parentNode = null. I don't know why, FF is really another person. *** to complete the function, item. form = null to judge, such:

If (obj = undefined | obj. form = null) return null;

IE does not store this problem.

Related Article

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.