validation using html & javascript

  1. this is a validation checking page using html and javascript
    the page will look like this

    you can make a file with html extension(example validation.html) and save the code below

    function verify()
    {
    var str = document.form1.name.value;
    //alert(str.length);
    var valid="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for(i=0;i<str.length;i++)
    {
    if(valid.indexOf(str.charAt(i)) ==-1)
    {
    alert("please insert alphabet for name");
    document.form1.name.value="";
    document.form1.name.focus();
    return false;
    }
    }
    if(document.form1.name.value=="")
    {
    alert("Please give the name");
    return false;
    }

    if(document.form1.email.value=="")
    {
    alert("Please give the email");
    return false;
    }

    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = document.form1.email.value;
    if(reg.test(address) == false) {
    alert('Invalid Email Address');
    return false;
    }

    var str = document.form1.age.value;
    //alert(str.length);
    var valid="0123456789";
    for(i=0;i<str.length;i++)
    {
    if(valid.indexOf(str.charAt(i)) ==-1)
    {
    alert("please insert Number for Age");
    document.form1.age.value="";
    document.form1.age.focus();
    return false;
    }
    }

    if(document.form1.age.value=="")
    {
    alert("Please give Age");
    document.form1.age.focus();
    return false;
    }

    if(document.form1.age.value 60)
    {
    alert("Please give Age range between 18 and 60");
    return false;
    }

    if(document.form1.gender[0].checked==false && document.form1.gender[1].checked==false )
    {
    alert("Please Select Gender");
    return false;
    }

    if(document.form1.language1.checked==false && document.form1.language2.checked==false && document.form1.language3.checked==false)
    {
    alert("Please Select your Choise of Language(At least One)");
    return false;
    }

    if(document.form1.country.value=="")
    {
    alert("Please give country");
    return false;
    }

    if(document.form1.myaddress.value=="")
    {
    alert("Please give Address");
    document.form1.myaddress.focus();
    return false;
    }

    if(document.form1.u_name.value=="")
    {
    alert("Please give username");
    document.form1.u_name.focus();
    return false;
    }
    if(document.form1.pass.value.length<6)
    {
    alert("Please give Password more than 5 Charecter");
    document.form1.pass.focus();
    return false;
    }
    if(document.form1.pass.value=="")
    {
    alert("Please give Password");
    document.form1.pass.focus();
    return false;
    }
    if(document.form1.r_pass.value=="")
    {
    alert("Please give Retype Password");
    document.form1.r_pass.focus();
    return false;
    }
    if((document.form1.pass.value)!= (document.form1.r_pass.value))
    {
    alert("password is not matching.");
    document.form1.r_pass.value="";
    document.form1.r_pass.focus();
    return false;
    }
    }

    Name
    Email
    Age
    Gender MaleFemale
    Language Hindi
    English
    Beangali
    country --Select--
    india
    pakastan
    beangladesh
    srilanka
    Address
    user name
    password
    Retype password

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s