Monday, 1 September 2014

form validations


<script>
function validateForm()
{
        var x = document.forms["myform"]["username"].value;

        if (x==null || x=="")
    {

        alert("First name must be filled out");
        return false;
    }
   

    var z = document.forms["myform"]["pass"].value;

        if (z==null || z=="")
    {

        alert("Password must be filled out");
        return false;
    }
        
        if((z.length < 6) || (z.length >10))
    {
        alert("Error: Password must contain at least six characters!");
       
         return false; }

    var a = document.forms["myform"]["mob"].value;
    if(isNaN(a))
    {
        alert("Enter the valid Mobile Number(Like : 9566137117)");
        return false;
    }
    if((a.length < 1) || (a.length > 10))
    {
        alert(" Your Mobile Number must be 1 to 10 Integers");
        return false;
    }


    var y = document.forms["myform"]["email"].value;
        var atpos = y.indexOf("@");
        var dotpos = y.lastIndexOf(".");
   
    if (atpos< 1 || dotpos<atpos+2 || dotpos+2>=y.length) {
        alert("Not a valid e-mail address");
        return false;
    }

}







</script>

No comments:

Post a Comment