Below is the code to validate email id and the password field in javascript on Login button click.
After successful validation will redirect from login page to Home Page.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script language="javascript" type="text/javascript">
function validate() {
var useridlength = document.getElementById('EmailID').value.length;
var passlength = document.getElementById('Pwd').value.length;
if (useridlength == 0) {
alert('Enter Email ID');
return;
}
else if (passlength < 8) {
alert('Password should be of 8 or more characters');
return;
}
var email = document.getElementById('EmailID');
var EmailExpression = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
if (!EmailExpression.test(email.value)) {
alert('Enter Proper Email ID');
return;
}
else {
window.location.href = "Home.aspx";// redirect page after login
}
}
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Email id:<input id="EmailID" type="text" /> <br />
Password:<input id="Pwd" type="text" />
<br />
<input id="Button2" type="button" value="Login" onclick="validate()" />
<br />
<hr />
</div>
</form>
</body>
</html>
No comments:
Post a Comment