Ajax registration application 2

Source: Internet
Author: User
Tags rtrim trim

The second part is three js files: common. js, passwordstrength. js, and prototype. js. Let's take a look at the code of the first common. js file:

// 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 });
}

The second js file, passwordstrength. js

// 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 );
  }
}

The third js file, please continue to view: ajax Register application 3

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.