Saturday, 29 April 2017

Validation for Email, text only, numbers only

Dear All,

See the code

-----------------------------------------------------------------------------------------------------------

<center>
<br><br>
<font color=BLACK>LOGIN   
<script>

function check()
{
    username=document.frm.username.value;
    password=document.frm.password.value;
    if(username=="")
    {
        alert('Enter username');
        document.frm.username.focus();
        return false;
    }
    else if (!/^[a-zA-Z]*$/g.test(username))//Ony a-z characters
     {
        alert("Invalid characters");
        document.frm.username.value='';
        document.frm.username.focus();
        return false;
    }
    else if(!/\S+@\S+\.\S+/.test(password))//Only Email
    {
        alert('Enter email in password');
        document.frm.password.value='';
        document.frm.password.focus();
        return false;
    }
    else if(isNaN(password))//Only numbers
    {
        alert('Enter number in password');
        document.frm.password.value='';
        document.frm.password.focus();
        return false;
    }
   
   
    return true;

   
}
</script>
<form name=frm action="logincheck.php" method=post onsubmit='return check()'>   
<table cellpadding=5>
<form action="logincheck.php" method=post>
<tr><td>USER NAME :<td><input type=text name=username><br>
<tr><td>PASSWORD  :<td><input type=text name=password>
</table>
<input type=submit value=submit>
</form>