Ajax verify that the registered user name is already registered code

Source: Internet
Author: User

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<script language= "JavaScript Tutorial" >

function Createxmlhttp ()
{
var xmlhttp=null
try{
Xmlhttp=new XMLHttpRequest ();
}
catch (e) {
Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
}
return (XMLHTTP);
}

function CheckUser (u_name) {
if ("" ==u_name)
{
usercheck.innerhtml = "<font color=red>x user name cannot be empty!" </font> "
Return
}
if ((u_name.length<3) | | (u_name.length>12))
{
usercheck.innerhtml = "<font color=red>x username is 3 to 12 characters!</font>"
Return
}

if (Checkifenglish (u_name) ==false) {
usercheck.innerhtml = "<font color=red>x username can only be alphanumeric and underline!</font>";
Return
}

var datatosend = "U_name=" +u_name;
var xmlhttp = createxmlhttp ();
Xmlhttp.open ("Post", "Usercheck.asp Tutorial", false);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlhttp.send (Datatosend);
var Strr=xmlhttp.responsetext;

if ("1000" ==STRR)
{
usercheck.innerhtml = "<font color=green>√ username" +u_name+ "has not been registered and can be used!" </font> "
}
else if ("2002" ==STRR)
{
usercheck.innerhtml = "<font color=red>x user name" +u_name+ "has been registered, please change username!" </font> "
}
}
</script>


<body>

<form id= "Form1" Name= "RegForm" method= "POST" action= "" >
<label>
Enter Password:
<input type= "type" name= "U_name" onblur= "checkuser (this);"/>
<div id= "Usercheck" ></div>
</label>
<label>
<input type= "Submit" name= "Submit" value= "Validation" onclick= "Checkpass ();" />
</label>


</form>
</body>

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.