This section of JS Code is a friend of mine. Now we can share it with you.
Common. JS files
// Reference the JS/CSS file;
Function include (path, type, title ){
VaR S, I, T;
If (arguments. Length <1 ){
Return;
}
If (arguments. Length = 1 ){
Type = "JS ";
}
Switch (type. tolowercase ()){
Case "CSS ":
T = Document. getelementsbytagname ("Link ");
For (I = 0; I <t. length; I ++ ){
If (T [I]. href & T [I]. href. indexof (PATH )! =-1 ){
Return;
}
}
S = Document. createelement ("Link ");
S. rel = "alternate stylesheet ";
S. type = "text/CSS ";
S. href = path;
S. Title = title;
S. Disabled = false;
Break;
Case "JS ":
Case "JavaScript ":
Default:
T = Document. getelementsbytagname ("script ");
For (I = 0; I <t. length; I ++ ){
If (T [I]. SRC & T [I]. SRC. indexof (PATH )! =-1 ){
Return;
}
}
S = Document. createelement ("script ");
S. type = "text/JavaScript ";
S. src = path;
Break;
}
VaR H = Document. getelementsbytagname ("head") [0];
H. appendchild (s );
}
// Character processing;
// Remove left and right spaces;
Function trim (s ){
Return rtrim (ltrim (s ));
}
// Remove the left space;
Function ltrim (s ){
Return S. Replace (/^/S */,"");
}
// Remove the right space;
Function rtrim (s ){
Return S. Replace (// s * $ /,"");
}
// Verify the information;
// Null character value;
Function isempty (s ){
S = trim (s );
Return S. Length = 0;
}
// Email;
Function isemail (s ){
S = trim (s );
VaR P =/^ [_/. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] + /.) {1, 4} [A-Z] {2, 3} $/I;
Return P. test (s );
}
// Number;
Function isnumber (s ){
Return! Isnan (s );
}
// Color value;
Function iscolor (s ){
S = trim (s );
If (S. length! = 7) return false;
Return S. Search (// # [a-fA-F0-9] {6 }/)! =-1;
}
// Mobile phone number;
Function ismobile (s ){
S = trim (s );
VaR P =/13/d {9 }/;
Return P. test (s );
}
// ID card;
Function iscard (s ){
S = trim (s );
VaR P =/^/d {15} (/d {2} [xX0-9])? $ /;
Return P. test (s );
}
// URL;
Function isurl (s ){
S = trim (s). tolowercase ();
VaR P =/^ http: // [A-Za-z0-9] +/. [A-Za-z0-9] + [// = /? % /-&_~ '@ [/]/': +!] * ([^ <>/"/"]) * $ /;
Return P. test (s );
}
// Phone;
Function isphone (s ){
S = trim (s );
VaR P =/^ (/d {3}/) | (/d {3 }/-))? (/(0/d {2, 3}/) | 0/d {2, 3 }-)? [1-9]/d {6, 7} $ /;
Return P. test (s );
}
// Zip;
Function iszip (s ){
S = trim (s );
VaR P =/^ [1-9]/d {5} $ /;
Return P. test (s );
}
// Double;
Function isdouble (s ){
S = trim (s );
VaR P =/^ [-/+]? /D + (/./d + )? $ /;
Return P. test (s );
}
// Integer;
Function isinteger (s ){
S = trim (s );
VaR P =/^ [-/+]? /D + $ /;
Return P. test (s );
}
// English;
Function isenglish (s ){
S = trim (s );
VaR P =/^ [A-Za-Z] + $ /;
Return P. test (s );
}
// Chinese;
Function ischinese (s ){
S = trim (s );
VaR P =/^ [/u0391-/uffe5] + $ /;
Return P. test (s );
}
// Double byte
Function isdoublechar (s ){
VaR P =/^ [^/x00-/xFF] + $ /;
Return P. test (s );
}
// Contains Chinese Characters
Function haschinesechar (s ){
VaR P =/[^/x00-/xFF]/;
Return P. test (s );
}
Function hasaccountchar (s ){
VaR P =/^ [a-zA-Z0-9] [a-zA-Z0-9 _-] {} $ /;
Return P. test (s );
}
Function limitlen (S, Min, max ){
S = trim (s );
If (S = "") return false;
If (S. Length <min) | (S. length> MAX ))
Return false;
Else
Return true;
}
// Function;
// Delayed events;
Function setdeferevent (type, action, time ){
If (TRIM (time). Length = 0) time = 1;
If (typeof (time )! = "Number") time = 1;
Switch (type. tolowercase ()){
Case "go ":
Window. setTimeout ("window. Location = '" + Action + "'", time );
Break;
Case "alert ":
Window. setTimeout ("alert ('" + Action + "')", time );
Break;
Case "JS ":
Case "JavaScript ":
Window. setTimeout ("'" + action. tostring () + "'", time );
Break;
Default:
Alert ("Nothing will do! ");
Break
}
}
Function addloadlistener (handler ){
If (typeof window. addeventlistener! = 'Undefined ')
Window. addeventlistener ('load', handler, false );
Else if (typeof document. addeventlistener! = 'Undefined ')
Document. addeventlistener ('load', handler, false );
Else if (typeof window. attachevent! = 'Undefined ')
Window. attachevent ('onload', Handler );
};
Function addeventlistener (element, eventtype, handler, capture)
{
Try
{
If (element. addeventlistener)
Element. addeventlistener (eventtype, handler, capture );
Else if (element. attachevent)
Element. attachevent ("On" + eventtype, Handler );
}
Catch (e ){}
};
Function removeeventlistener (element, eventtype, handler, capture)
{
Try
{
If (element. removeeventlistener)
Element. removeeventlistener (eventtype, handler, capture );
Else if (element. detachevent)
Element. detachevent ("On" + eventtype, Handler );
}
Catch (e ){}
};
// Image;
Function preloadimages (){
VaR d = document;
If (D. Images ){
If (! D. p_ I _a) D. p_ I _a = new array ();
VaR I, j = D. p_ I _a.length, A = arguments;
For (I = 0; I <A. length; I ++ ){
D. p_ I _a [J] = new image ();
D. p_ I _a [J ++]. src = A [I];
}
}
}
// Ajax functions;
Function loadajaxelement (E, U, P, F, L ){
If (arguments. Length <3 ){
Return;
}
O = $ (E );
O. innerhtml = L;
P = $ h (P). toquerystring ();
New Ajax. Updater (
{Success: e },
U,
{Method: 'get', parameters: P, onfailure: f });
}
Function loadajaxdata (u, P, S, f ){
If (arguments. Length <3 ){
Return;
}
P = $ h (P). toquerystring ();
New Ajax. Request (
U,
{Method: 'get', parameters: P, onsuccess: S, onfailure: f });
}
Function sendajaxelement (E, U, P, F, L ){
If (arguments. Length <3 ){
Return;
}
O = $ (E );
O. innerhtml = L;
P = $ h (P). toquerystring ();
New Ajax. Updater (
{Success: e },
U,
{Method: 'post', parameters: P, onfailure: f });
}
Function sendajaxdata (u, P, S, f ){
If (arguments. Length <3 ){
Return;
}
P = $ h (P). toquerystring ();
New Ajax. Request (
U,
{Method: 'post', parameters: P, onsuccess: S, onfailure: f });
}
Passwordstrength. JS files
// Password strength;
Function passwordstrength (showed ){
This. Showed = (typeof (showed) = "Boolean ")? Showed: true;
This. styles = new array ();
This. styles [0] = {backgroundcolor: "# ebebeb", borderleft: "solid 1px # ffffff", borderright: "solid 1px # bebebe", borderbottom: "solid 1px # bebebe "};
This. styles [1] = {backgroundcolor: "# ff4545", borderleft: "solid 1px # ffffff", borderright: "solid 1px # bb2b2b", borderbottom: "solid 1px # bb2b2b "};
This. styles [2] = {backgroundcolor: "# ffd35e", borderleft: "solid 1px # ffffff", borderright: "solid 1px # e9ae10", borderbottom: "solid 1px # e9ae10 "};
This. styles [3] = {backgroundcolor: "#95eb81", borderleft: "solid 1px # ffffff", borderright: "solid 1px # 3bbc1b", borderbottom: "solid 1px # 3bbc1b "};
This. Labels = ["weak", "medium", "strong"];
This. divname = "pwd_div _" + math. Ceil (math. Random () * 100000 );
This. minlen = 5;
This. width = "150px ";
This. Height = "16px ";
This. content = "";
This. selectedindex = 0;
This. INIT ();
}
Passwordstrength. Prototype. init = function (){
VaR S = '<Table cellpadding = "0" id = "' + this. divname + '_ table "cellspacing =" 0 "style =" width:' + this. width + '; Height:' + this. height + '; "> ';
S + = '<tr> ';
For (VAR I = 0; I <3; I ++ ){
S + = '<TD id = "' + this. divname + '_ TD _' + I + '"width =" 33% "align =" center "> <span style =" font-size: 1px "> & nbsp; </span> <span id = "'+ this. divname + '_ label _' + I + '"style =" display: none; font-family: Courier New, courier, Mono; font-size: 12px; color: #000000; "> '+ this. labels [I] + '</span> </TD> ';
}
S + = '</tr> ';
S + = '</table> ';
This. content = s;
If (this. Showed ){
Document. Write (s );
This. copytostyle (this. selectedindex );
}
}
Passwordstrength. Prototype. copytoobject = function (O1, O2 ){
For (var I in O1 ){
O2 [I] = O1 [I];
}
}
Passwordstrength. Prototype. copytostyle = function (ID ){
This. selectedindex = ID;
For (VAR I = 0; I <3; I ++ ){
If (I = ID-1 ){
This. $ (this. divname + "_ label _" + I). style. Display = "inline ";
} Else {
This. $ (this. divname + "_ label _" + I). style. Display = "NONE ";
}
}
For (VAR I = 0; I <ID; I ++ ){
This. copytoobject (this. styles [ID], this. $ (this. divname + "_ TD _" + I). Style );
}
For (; I <3; I ++ ){
This. copytoobject (this. styles [0], this. $ (this. divname + "_ TD _" + I). Style );
}
}
Passwordstrength. Prototype. $ = function (s ){
Return document. getelementbyid (s );
}
Passwordstrength. Prototype. setsize = function (W, h ){
This. width = W;
This. Height = h;
}
Passwordstrength. Prototype. setminlength = function (n ){
If (isnan (N )){
Return;
}
N = number (N );
If (n> 1 ){
This. minlength = N;
}
}
Passwordstrength. Prototype. setstyles = function (){
If (arguments. Length = 0 ){
Return;
}
For (VAR I = 0; I <arguments. Length & I <4; I ++ ){
This. styles [I] = arguments [I];
}
This. copytostyle (this. selectedindex );
}
Passwordstrength. Prototype. Write = function (s ){
If (this. Showed ){
Return;
}
VaR n = (S = 'string ')? This. $ (s): S;
If (typeof (n )! = "Object "){
Return;
}
N. innerhtml = This. content;
This. copytostyle (this. selectedindex );
}
Passwordstrength. Prototype. Update = function (s ){
If (S. Length <this. minlen ){
This. copytostyle (0 );
Return;
}
VaR ls =-1;
If (S. Match (/[A-Z]/ig )){
Ls ++;
}
If (S. Match (/[0-9]/ig )){
Ls ++;
}
If (S. Match (/(. [^ a-z0-9])/ig )){
Ls ++;
}
If (S. length <6 & LS> 0 ){
Ls --;
}
Switch (LS ){
Case 0:
This. copytostyle (1 );
Break;
Case 1:
This. copytostyle (2 );
Break;
Case 2:
This. copytostyle (3 );
Break;
Default:
This. copytostyle (0 );
}
}