A very powerful complete Web Form validator

Source: Internet
Author: User
Tags date object min regular expression return static class zip
web| Form Validation | The validation of the program form has been a headache for web designers, and the form validation class validator is written to address this problem, designed to liberate designers from complex forms validation and focus on web design and functional improvements.

Validator is a custom property of a pseudo static class and object based on JavaScript technology, which validates the form entry in a Web page, allows multiple forms to be validated simultaneously on the same page, and, after familiarity with the interface, validates a particular form item or even just a string. Because it is a pseudo static class, you do not need to instantiate it at call time, directly with the class name +. Syntax + property or method name. In addition, validator provides 3 different error hint modes to meet different needs.

Full document Download: Validator.chm (zip compression, 111K)

Validator currently achievable types of authentication are:

1. Whether it is empty;
2. Chinese characters;
3. Double Byte character
4. English;
5. Number;
6. Integers;
7. Real numbers;
8.Email address;
9. Web sites using the HTTP protocol;
10. Telephone number;
11. Currency;
12. mobile phone number;
13. zip Code;
14. ID card number;
15.QQ number;
16. Date;
17. The password which complies with the safety rule;
18. Duplicate value of a certain item;
19. Comparison of the relationship between two numbers;
20. Determine whether the input value is in (n, m) interval;
21. Enter character length limits (can be compared by byte);
22. For the selection of a radio button with the same name to judge;
23. Limit the number of selected multiple-selection buttons with the same name;
24. Custom regular expression validation;

Operating Environment (client):

Tested with IE6.0+SP1 and Mozilla Firefox 1.0 under Windows Server 2003;
The Netscape test was passed under LUnix RedHat 9;


Default:

Alert (this. Errormessage.join ("\ n"));

Break

}

return false;

}

return true;

},

Limit:function (Len,min, max) {

min = Min | | 0;

max = Max | | Number.MAX_VALUE;

return min <= len && len <= Max;

},

Lenb:function (str) {

Return Str.replace (/[^\x00-\xff]/g, "* *"). Length;

},

Clearstate:function (elem) {

With (Elem) {

if (Style.color = = "Red")

Style.color = "";

var lastnode = parentnode.childnodes[parentnode.childnodes.length-1];

if (lastnode.id = = "__errormessagepanel")

Parentnode.removechild (Lastnode);

}

},

Adderror:function (index, str) {

This. Erroritem[this. Erroritem.length] = this. Erroritem[0].elements[index];

This. Errormessage[this. Errormessage.length] = this. Errormessage.length + ":"
+ str;

},

Exec:function (OP, Reg) {

return new RegExp (Reg, "G"). Test (OP);

},

Compare:function (OP1,OPERATOR,OP2) {

Switch (operator) {

Case "NotEqual":

Return (OP1!= OP2);

Case "GreaterThan":

Return (Op1 > OP2);

Case "Greaterthanequal":

Return (OP1 >= OP2);

Case "LessThan":

Return (OP1 < OP2);

Case "Lessthanequal":

Return (OP1 <= OP2);

Default

return (OP1 = = OP2);

}

},

Mustchecked:function (name, Min, max) {

var groups = Document.getelementsbyname (name);

var haschecked = 0;

min = Min | | 1;

max = Max | | Groups.length;

for (Var i=groups.length-1;i>=0;i--)

if (groups[i].checked) haschecked++;

return min <= haschecked && haschecked <= Max;

},

Isdate:function (OP, formatstring) {

formatstring = formatstring | | "Ymd";

var m, year, month, day;

Switch (formatstring) {

Case "YMD":

m = Op.match (New RegExp ("^\\s*" (\\d{4}) | ( \\D{2})) ([-./]) (\\d{1,2}) \\4 (\\d{1,2}) \\s*$));

if (M = = null) return false;

Day = m[6];

month = m[5]--;

Year = (M[2].length = 4)? M[2]: getFullYear (parseint (m[3), 10));

Break

Case "DMY":

m = Op.match (New RegExp ("^\\s* (\\d{1,2}) ([-./]) (\\d{1,2}) \\2 ((\\d{4}) | ( \\D{2})) (\\s*$));

if (M = = null) return false;

Day = m[1];

month = m[3]--;

Year = (M[5].length = 4)? M[5]: getFullYear (parseint (m[6), 10));

Break

Default:

Break

}

var date = new Date (year, month, day);

return (typeof date = = "Object" && year = = Date.getfullyear ()
&& month = = Date.getmonth () && day = Date.getdate ());

function getFullYear (y) {return (y<30?) "20": "19") +
Y) |

}

}




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.