TD>
TR>
form>
TABLE>
/ **************************************************
Validator v1.03
Code by my Foshan people
Wfsr@msn.com************************************************************* **** /
Validator = {
REQUIRE: /. /,
Email: /^/w ([- .]/w ) *@/w ([w w )**/w ([-.]/w ) * *
Phone: / ^ (/ (/ D {3} /) | (/ d {3} / -))))? (/ (0 / d {2, 3} /) | 0 / d {2,3} -)? [1-9] / d {6,7} (/ - / d {1, 4})? $ /,
Mobile: / ^ ((/ (/ D {3} /) | (/ d {3} / -))? 13 / d {9} $ /,
URL: /^http:[A-ZA-Z0-9] /.[A-ZA-Z0-9] [//=/?%/-&_~`@ /]/': !] * ([^ <> / "]) * $ /,
IDCARD: / ^ / d {15} (/ d {2} [a-za-z0-9])? $ /,
Currency: /^/d (/./d )? /
Number: / ^ / d $ /,
ZIP: / ^ [1-9] / d {5} $ /,
QQ: / ^ [1-9] / d {4, 8} $ /,
Integer: / ^ [- / ]? / D $ /,
Double: /^[-/ ]?/d (/./d )?/,
English: / ^ [A-ZA-Z] $ /,
CHINESE: / ^ [/ u0391- / uffe5] $ /,
UserName: / ^ [a-z] / w {3,} $ / i,
Unsafe: /^(([AZ]*|[Az]*|/d*|[-_//~!@#/$%/^&/*/ (/ )/[/]/ (/} <> /? / '/ "] *) |. {0,5}) $ | / s /,
Issafe: Function (STR) {Return! This.unsafe.test (str);},
Safestring: "this.issafe (value)",
Limit: "THIS.LIMIT (Value.length), GetAttribute ('max')",
Limitb: "this.limit (this.lenb (value), GetAttribute ('MAX')",
Date: "this.Isdate (Value, GetaTtribute ('min'), GetAttribute ('Format')",
Repeat: "Value == Document.GtelementsByName (GetAttribute ('to')) [0] .value",
Range: "GetaTribute ('min') <(value | 0) && (Value | 0)
Compare: "this.compare (Value, GetAttribute ('Operator'), GetAttribute ('to'))",
Custom: "THIS.EXEC (Value, GetaTtribute ('regexp'))",
Group: "this.MustChecked (GetAttribute ('MIN'), GetAttribute ('max')", ErrorItem: [Document.Forms [0]],
ErrorMessage: ["The following reasons lead to failure: / t / t / t / t"],
Validate: Function (theform, mode) {
Var obj = theform || Event.srcelement;
Var count = obj.elements.length;
THIS.ERRORMESSAGE.LENGTH = 1;
THIS.ERRORITEM.LENGTH = 1;
THIS.ERRORITEM [0] = OBJ;
FOR (var i = 0; i
With (Obj.elements [i]) {
Var _Datatype = GetAttribute ("Datatype");
IF (TypeOf (_DataType) == "Object" || TypeOf (this [_datatype]) == "undefined") Continue;
this.clearstate (Obj.elements [i]);
IF ("Require" == "False" && value == ") Continue;
Switch (_DataType) {
Case "Date":
Case "repeat":
Case "Range":
Case "Compare":
Case "Custom":
Case "group":
Case "limit":
Case "limitb":
Case "Safestring":
if (! Eval (this [_DataType])) {
This.Adderror (I, GetAttribute ("msg"));
}
Break;
DEFAULT:
IF (! this [_datatype] .test (value)) {
This.Adderror (I, GetAttribute ("msg"));
}
Break;
}
}
}
IF (this.ErrorMessage.Length> 1) {
Mode = MODE || 1;
Var errcount = this. errorItem.length;
Switch (MODE) {
Case 2:
For (var i = 1; i
THIS.ERRORITEM [I] .style.color = "red";
Case 1:
Alert (this.ErrorMessage.Join);
THIS.ERRORITEM [1] .focus ();
Break;
Case 3:
For (var i = 1; i
Try {
Var span = document.createElement ("span");
Span.id = "__ERRORMESSAGEPANEL";
Span.style.color = "red"; this.ErrorItem [i] .parentnode.appendchild (span);
Span.innerhtml = this.ErrorMessage [i] .replace (// D : /, "*");
}
Catch (e) {Alert (E.DESCRIPTION);
}
THIS.ERRORITEM [1] .focus ();
Break;
DEFAULT:
Alert (this.ErrorMessage.Join);
Break;
}
Return False;
}
Return True;
}
Limit: Function (LEN, MIN, MAX) {
min = min ||;
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
Case "Lessthanequal":
Return (OP1 <= OP2);
DEFAULT:
Return (OP1 == OP2);
}
}
MustChecked: Function (Name, min, max) {
Var groups = document.getlementsByname (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 ("^
//d{4} )| (/d {]) (/ d) (/ d) (/d {1, 2}) //4(//d 1, 2}) $ ") );
IF (m == null) Return False;
Day = m [6];
Month = m [5] * 1;
Year = (M [2] .length == 4)? M [2]: getFullyear (Parseint (M [3], 10));
Break;
Case "DMY":
M = op.match (new regexp ("^
//d 1 1 2 2 (({{{| | | | | | $ $ | $ $ $ $ $ $ ));
IF (m == null) Return False;
Day = m [1];
Month = m [3] * 1;
Year = (M [5] .length == 4)? M [5]: getFullyear (Parseint (M [6], 10));
Break;
DEFAULT:
Break;
}
IF (! PARSEINT (MONTH)) RETURN FALSE;
Month = month == 0? 12: month;
Var Date = New Date (Year, Month-1, Day);
Return (Typeof (Date) == "Object" && year == Date.getFullyEar () && month == (Date.getMonth () 1) && day == Date.getdate ());
Function getFullyear (Y) {RETURN ((Y <30? "20": "19") Y) | 0;}
}
}
script>
body>
转载请注明原文地址:https://www.9cbs.com/read-62342.html
|