validation in client side with coding example

java script validation in client side with explanation and give an example for 3tier achitecture with simple examples


6 Answers
1-6 of  6
6 Answers
  • JavaScript Form Validation
    HTML form validation can be done by JavaScript.

    If a form field (fname) is empty, this function alerts a message, and returns false, to prevent the form from being submitted:

    Data Validation
    Data validation is the process of ensuring that user input is clean, correct, and useful.

    Typical validation tasks are:

    has the user filled in all required fields?
    has the user entered a valid date?
    has the user entered text in a numeric field?
    Most often, the purpose of data validation is to ensure correct user input.

    Validation can be defined by many different methods and deployed in many different ways.

    Server-side validation is performed by a web server after the input has been sent to the server.

    Client-side validation is performed by a web browser before the input is sent to a web server.

    HTML Constraint Validation
    HTML5 introduced a new HTML validation concept called constraint validation.

    HTML constraint validation is based on:

    Constraint validation HTML Input Attributes
    Constraint validation CSS Pseudo Selectors
    Constraint validation DOM Properties and Methods


    <!DOCTYPE html>
    <html>
    <head>
    <script>
    function validateForm() {
        var x = document.forms["myForm"]["fname"].value;
        if (x == "") {
            alert("Name must be filled out");
            return false;
        }
    }
    </script>
    </head>
    <body>

    <form name="myForm" action="/action_page.php"
    onsubmit="return validateForm()" method="post">
    Name: <input type="text" name="fname">
    <input type="submit" value="Submit">
    </form>

    </body>
    </html>

  • function ValidateEmail(mail) { var objVal = document.getElementById(mail).value; var obj = document.getElementById(mail); var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; //var address = document.getElementById[email].value; if (reg.test(objVal) == false) { alert("You have entered an invalid email address!"); obj.classList.add("cui-requredField"); obj.focus(); return (false); } else obj.classList.remove("cui-requredField"); return (true); }

  • //body
    <form>
    <input type="text" id="name">Name:
    <label style="display:none; color:red;" id="namelabel">Please enter Name</label>
    <input type="text" id="email">Email: 
    <label style="display:none; color:red;" id="emaillabel">Please enter Email</label>
    <button onclick="submit();">Submit</button>
    </form>
    //script
    function submit(){
    if(document.getElementById("name").value == ""){
    $("#namelabel").show();
    $("#name").focus();
    return -1;
    }else{
    $("#namelabel").hide();
    }
    if(document.getElementById("email").value == ""){
    $("#emaillabel").show();
    $("#email").focus();
    return -1;
    }else{
    $("#emaillabel").hide();
    }
    }

  • JAVASCRIPT VALIDATION EG: Data Validation
    Username
    Password
    Mobile no
    email

Javascript

Didn't get the answer.
Contact people of Talent-Javascript directly by clicking here