Sunday, June 28, 2026

Example 2: Validate Name, Email, and Mobile Number

 <!DOCTYPE html>

<html>

<head>

<script>

function validate() {


    var name = document.getElementById("txtName").value;

    var email = document.getElementById("txtEmail").value;

    var mobile = document.getElementById("txtMobile").value;


    if (name == "") {

        alert("Please enter your name.");

        return;

    }


    if (email == "") {

        alert("Please enter your email.");

        return;

    }


    if (!email.includes("@")) {

        alert("Invalid Email Address.");

        return;

    }


    if (mobile.length != 10) {

        alert("Mobile number must be 10 digits.");

        return;

    }


    alert("Form Submitted Successfully!");

}

</script>

</head>


<body>


<h2>Student Registration</h2>


Name:

<input type="text" id="txtName"><br><br>


Email:

<input type="text" id="txtEmail"><br><br>


Mobile:

<input type="text" id="txtMobile"><br><br>


<button onclick="validate()">Submit</button>


</body>

</html>

No comments:

Post a Comment

Data Transfer Java Script using Local Storage

  Page 1: index.html <!DOCTYPE html> <html> <head> <title> Page 1 </title> </head> <body> ...