Formvalidate form validation feature code updates and provides download _javascript tips

Source: Internet
Author: User
Formvalidate Feature Update

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

More usage, can be joined:

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

Add Method:
Extend
Add validation mode 4, same as 3, but stop checking down immediately when validation does not pass. Under Mode 3, if an error occurs, the error is logged and checked down, and Mode 4 is not checked down.


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: "Please enter your name!" Length must be greater than 2, less than 3 "},
{name: ' birthday[0] ', Required:false, type: "Date", msg: "Date of birth is optional, if entered, please enter the correct date"},
{name: "email[0]", Required:false, type: "Email", msg: "Mail is optional, if entered, please enter the correct email address"},
{name: "scorea[0]", Required:true, type: "Num", min:0, max:100, msg: "Language score is mandatory, must be greater than 0 less than 100"},
{name: "scoreb[0]", Required:true, type: "Num", min:0, max:100, msg: "Math score is mandatory, must be greater than 0 less than 100"},
{name: "scorec[0]", Required:true, type: "Num", min:0, max:100, msg: "English score is mandatory, must be greater than 0 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);

Explain:
Why do you write that?
If you do not add a form item dynamically, you can delete the va.extend sentence. But dynamically adding table items ... The new form item cannot be specified.
This is written to follow the validation rules specified by RULETPL. This ruletpl can be any string (not its value), for example, if you replace RULETPL with TTT, then write:
Va.extend (Document.forms[0], ' TTT ', checkrule)
RULETPL is a custom attribute for a table item, the value must be a subscript for the checkrule, and if this subscript does not exist, the item is not checked by default. Otherwise, the selected Checkrule elements are copied again to achieve the purpose of dynamically adding validation rules.

In addition to this feature, I met a few interesting questions, and I said here:

1, address reference, please do not run, say the following code, the value of variable A.

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}], then you are wrong, the true value is:
A = [{name:2},{name:2}];

The reason is very simple, because the push is an object, the object in JS is address reference, so, A[tmp-1].name = 2, in fact, is the value of a[0] changed.

The following paragraph is very simple, value reference, does not occur above.


var a = [1,2,3];
A.push (A[a.length-1]);
alert (a);
A[A.LENGTH-1] = 4;
alert (a);
Dynamically deletes a form item under 2,FF.
If a form item is deleted dynamically, form[' ItemName ' or the deleted form item is not alert.
At this time, its parentnode,form are null, but can not use parentnode = NULL to judge, do not know why, FF is really another person * * *, in order to complete the function, had to use Item.form = NULL to judge, such as:

if (obj = = Undefined | | obj.form = NULL) return null;

IE does not save this problem.

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.