Follow by Email

Tuesday, April 23, 2013

validate email id and password in javascript

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" "">
<html xmlns="">
<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');


            else if (passlength < 8) {
                alert('Password should be of 8 or more characters');

            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');

            else {
                window.location.href = "Home.aspx";// redirect page after login


    <form id="form1" runat="server">
        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 />

Protected by Copyscape Duplicate Content Detection Tool