Ajax Authentication Login Registration

Source: Internet
Author: User

<form id= "Form1" onsubmit= "return false;" >
<table id= "Login-table" >
<tr>
&LT;TD width= ">" No.:</td>
<td><input class= "textbox" type= "text" style= "width:160px;" id= "txtUserName"
Maxlength= "9" onblur= "Checkusername ()" onclick= "$.trim (this.value)"/><span></span>
</td>
</tr>
<tr>
&LT;TD width= "" > Password:</td>
<td><input class= "textbox" type= "Password" style= "width:160px;" id= "Txtuserpwd"
Onblur= "Checkuserpwd ()" onclick= "$.trim (this.value)"/><span></span>
</td>
</tr>
<tr>
&LT;TD width= "Up" > Verification Code:</td>
<td><input class= "textbox" type= "text" style= "width:160px;" maxlength= "5"
Id= "Txtcheckcode" onblur= "Checkcheckcode ()" onclick= "$.trim (this.value)"/><span>
</span>
</td>
</tr>
<tr>
&LT;TD width= "></td>"
<td><div style= "color: #808080;" > characters in input, case insensitive </div><br/>

<a href= "#" id= "Change_image" > can't see Clearly, change a </a></td>
</tr>
<tr>
&LT;TD width= "></td>"
<td><input type= "image" Src= "app_themes/images/btn_login.jpg" id= "Btnlogin"
alt= "Login Now" style= "border:0;" /></td>
</tr>
</table>
</form>


<script language= "javascript" type= "Text/javascript" >
$ (document). Ready (function () {
//Verification Code update
$ (' #change_image '). Click (
Function () {
$ (' #imgCheckCode '). attr (' src ', ' checkcode.aspx? ') +math.random ());
});
//Key code
$ ("#btnLogin"). Click (function () {
if (checkusername () && checkuserpwd () && Checkcheckcode ())
{
var data = {
UserName: $ (' #txtUserName '). Val (),
Userpwd: $ (' #txtUserPwd '). Val (),
Checkcode: $ (' #txtCheckCode '). Val ()
};
//Submit data to Login.ashx page processing
$.post ("Ajax/login.ashx", data,function (Result) {
if (result = = "1")//Login successful
{
Alert ("Login successful! You can do something else! ");
//Close the simulation window
Window.parent.window.jBox.close ();
}
Else if (result = = "2")//Authenticode error
{
$ (' #txtCheckCode '). Next ("span"). CSS ("Color", "red"). Text ("*
Verification code Error ");
}
Else
{
Alert ("Login failed! Please try again ");
}
});
}
Else
{
Checkusername ();
Checkuserpwd ();
Checkcheckcode ();
}
});
});

Check the UserName
function Checkusername ()
{
if ($ ("#txtUserName"). Val (). length = = 0)
{
$ ("#txtUserName"). Next ("span"). CSS ("Color", "red"). Text ("* User name is not empty");
return false;
}
Else
{
var reg =/^\d{9}$/;
if (!reg.test ($ (' #txtUserName '). Val ()))
{
$ (' #txtUserName '). Next ("span"). CSS ("Color", "red"). Text ("* Correct format
such as: 030602888 ");
return false;
}
Else
{
$ ("#txtUserName"). Next ("span"). CSS ("Color", "red"). Text ("");
return true;
}
}
}
Check the PWD
function Checkuserpwd ()
{
if ($ (' #txtUserPwd '). Val (). length = = 0)
{
$ (' #txtUserPwd '). Next ("span"). CSS ("Color", "red"). Text ("* Password is not empty");
return false;
}
Else
{
$ (' #txtUserPwd '). Next ("span"). CSS ("Color", "red"). Text ("");
return true;
}
}
Check the check code
function Checkcheckcode ()
{
if ($ (' #txtCheckCode '). Val (). length = = 0)
{
$ (' #txtCheckCode '). Next ("span"). CSS ("Color", "red"). Text ("* Verification code is not empty");
return false;
}
Else
{
$ (' #txtCheckCode '). Next ("span"). CSS ("Color", "red"). Text ("");
return true;
}
}

Ajax Authentication Login Registration

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.