HTML code <Div class = "mtitle"> <span> User name: </span> </div>
<Div class = "mright"> <input name = "username" type = "text" id = "username" maxlength = "20" size = "20"
Class = "colorblue" onfocus = "This. classname = 'colorfocal ';"
Onblur = "This. classname = 'colorblu'; checkusername (this. Value);"/>
<Span id = "checkresult"> up to 20 characters </span> </div>
JavaScript code Function checkusername (username)
{
VaR unlen = username. Replace (/[^ \ x00-\ xFF]/g, "**"). length; // two characters are counted if the input is not an ASCII Value
If (unlen <3 | unlen> 20 ){
Document. getelementbyid ("checkresult"). innerhtml = "<font color = '#009900'>"
+ (Unlen <3? Profile_username_tooshort: profile_username_toolong) + "</font> ";
Return;
}
Ajaxread ("tools/ajax. aspx? T = checkusername & username = "+ escape (username ),
"Showcheckresult (OBJ, '" + username + "');");
}
// Escape
(Charstring) is Unicode conversion for string objects so that they can be read on all computers. All spaces, punctuation marks, accents, and other non-
ASCII characters are replaced by % XX encoding. XX indicates the hexadecimal number of the character. For example, "% 20" is returned by a space ". The character value must be greater than %
Uxxxx format storage. Unescape is a reverse operation.
// Obtain the original character in Ajax. aspx using the system. Web. httputility. urldecode () method
Function showcheckresult (OBJ, username)
{
VaR res = obj. getelementsbytagname ('result'); // search for the node of the result label in XML
VaR rescontainer = Document. getelementbyid ("checkresult ");
VaR result = "";
If (RES [0]! = NULL & res [0]! = Undefined)
{
If (RES [0]. childnodes. length> 1 ){
Result = res [0]. childnodes [1]. nodevalue;
} Else {
Result = res [0]. firstchild. nodevalue;
}
}
If (result = "1 ")
{
Rescontainer. innerhtml = "<font color = '#009900'> sorry, you entered the USERNAME \" "+ htmlencode (username, true, 4) + "\" has been used or disabled by others. Please select another name and try again. </Font> ";
}
Else
{
Rescontainer. innerhtml = profile_username_pass;
}
}
Function createxmlhttp (){
If (window. XMLHttpRequest ){
Return new XMLHttpRequest ();
} Else if (window. activexobject ){
Return new activexobject ("Microsoft. XMLHTTP ");
}
Throw new error ("XMLHTTP object cocould be created .");
}
Function ajaxread (file, fun ){
VaR xmlobj = createxmlhttp ();
Xmlobj. onreadystatechange = function (){
If (xmlobj. readystate = 4 ){
If (xmlobj. Status = 200 ){
OBJ = xmlobj. responsexml; // the value assigned to the OBJ variable is UTF-8 encoded.
Eval (fun); // execute the Javascript statement in the fun string
}
Else {
Alert ("error: [" + xmlobj. Status + "]");
}
}
}
Xmlobj. Open ('get', file, true );
Xmlobj. Send (null );
}