Ticker

6/recent/ticker-posts

Validation



How JavaScript used validato

When we create a website & then that website a number of Web Pages, Each web page performs different tasks depending upon the developer what type of task performs on that particular web page. The page is only used for  reading view purposes only or they want to retrieve the information from the user input from that particular web page in the form of such as (Registration web page form).,But when they want to retrieve the information on that Registration Form. The Developer set a number of validations on that Registration web page form. Some validation set on Registration Form when we Input from the user that Registration Form given below.client-side & server-side scripting  validation apply on website depends upon the situation. 

1 User do not not leave the TextBox without enter the TextBok Form not accept

2 Whether the user selects or not Drop-down List/ListBox/ComboBox/Radio Button/Radio Button Checked.

3 TextBox Value either text or number

4 How much text or value enter in particular TextBox (minimum width set)

5 Email or Form validation, (such as special character, number, string, space not allowed etc checked through )

Password TextBox (password show or not password length etc)

7 Apply on TextBox such as checking whether we used a single line or Multiple line and many more validation sets on a particular website when we created a website.

These types of above restrictions are called validation. It is the process for search error in your web page. All debugging in a website through it. When you run your HTML & CSS through the validator you have no any type of error when validation apply & correct data retrieve from the user and stored it into a Back-end Server.  It also uses tools such as native tools. This tool applies HTML5 validation, certain advantages over query plug-in .Native- validation is used at Browser level, its means users do not download and enter external scripts. There are so many websites in the market that use native validation. Native validation is mostly used because it automatically translates error messages into User language. In other ways JavaScript validation is also rich in feature HTML5 pickup the number of validation depends upon the condition it uses a validation library. JavaScript validation also provides a theme-able message that the user immediately responds to. JavaScript validation automatically provides a message for error as per the user region but it's difficult to customize these types of messages. In java scripting url and email validation are much familiar the number and range input provided from the user and all the control using occur these validation rules applied by the developer.

Example below:

<html>

<head>

  <title>How to set  Registration Form validation</title>

  <script type="text/javascript">

    var divs = new Array();

    divs[0] = "errName";

    divs[1] = "errSurname";

    divs[2] = "errEmailaddress";

    divs[3] = "errUser";

    divs[4] = "errPwd";

    divs[5] = "errCpwd";

    function validate()

{

      var inputs = new Array();

      inputs[0] = document.getElementById('name').value;

      inputs[1] = document.getElementById('surname').value;

      inputs[2] = document.getElementById('emailadr').value;

      inputs[3] = document.getElementById('user').value;

      inputs[4] = document.getElementById('pass').value;

      inputs[5] = document.getElementById('cpass').value;

      var fr = new Array();

      fr[0] = "<div>Please enter your firstname!</div>";

      fr [1] = <div>Please enter your surname!</div.>";

      fr [2] = <div>Please enter your emailaddress!</.div>";

      fr [3] = <div>Please enter your user!</div->";

      fr [4] = <div>Please enter your password!</_div>";

      fr [5] = <div>Please enter your confirm password!</div’>";

      for (j. in input){

        var errMessage = fr [.j];

        var div = divs[j];

        if (inputs[j] == "")

        document.getElementById(div).innerHTML = errMessage;

        else if (i==2)

        {

          var atpos=input[i].indexOf("@");

          var dotpos=input[i].lastIndexOf(".");

          if (apos<1 || dpos<apos+2 || dpos+2>=inputs[i].length)

        document.getElementById('errEmailaddress').innerHTML = "<div style='color: red'>Plz  valid email address!</div>";

          else

        document.getElementById(div).innerHTML = "OK!";

        }

        else if (i==5)

        {

          var fl = document.getElementById('pass').value;

          var sc = document.getElementById('cpass').value;

          if (sc != fl)

        document.getElementById('errCpwd').innerHTML = "<div'>Password Mismatch</div>";

          else

        document.getElementById(div).innerHTML = "OK!";

        }

        else

        document.getElementById(div).innerHTML = "OK!";

       }

     }

        function finalValidate()

        {

          var cnt = 0;

          for(i=0;i<6;i++)

          {

            var div = divs[i];

            if(document.getElementById(div).innerHTML == "Well")

            cnt = cnt ++;

          }

          if(cnt == 5)

          document.getElementById("errFinal").innerHTML = "Data correct!!!";

        }

   </script>

</head>

<body>

<table id="table1">

      <tr>

        <td>Name:</td>

        <td><input type="text" id="name" onkeyup="validate();" /></td>

        <td><div id="errName"></div></td>

      </tr>

      <tr>

        <td>Last Name:</td>

        <td><input type="text" id="surname" onkeyup="validate();"/></td>

        <td><div id="errSurname"></div></td>

      </tr>

      <tr>

        <td>Email:</td>

        <td><input type="text" id="emailadr" onkeyup="validate();"/></td>

        <td><div id="errEmailaddress"></div></td>

      </tr>

      <tr>

        <td>User Id:</td>

        <td><input type="text" id="user" onkeyup="validate();"/></td>

        <td><div id="errUser"></div></td>

      </tr>

      <tr>

        <td>Password:</td>

        <td><input type="password" id="pass" onkeyup="validate();"/></td>

        <td><div id="errPwd"></div></td>

      </tr>

      <tr>

        <td>Confirm Password:</td>

        <td><input type="password" id="cpass" onkeyup="validate();"/></td>

        <td><div id="errCpwd"></div></td>

      </tr>

      <tr>

        <td><input type="button" id="create" value="Register" onclick="validate();finalValidate();"/></td>

        <td><div id="errFLR"></div></td>

      </tr>

</table>

</body>

</html>

</body>

</html>

For more understanding you can also read below mentioned topic from online:

javascript validation before form submit


Post a Comment

0 Comments