JavaScript Program to validate an email address

Pranat
0
Lamp

 <!DOCTYPE html>

<html >

<head>

    <title>Email Validation</title>

    <script>

        function validatEmail(emailId)

        {

            var mailformat = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

            if(emailId.value.match(mailformat))

            {

                document.form1.text1.focus();

                return true;

            }

            else

            {

                alert("Invalid email address.");

                document.form1.text1.focus();

                return false;

            }

        }

    </script>

</head>

<body>

    

    <div>

        <h2>Javascript email Validation</h2>

        <form name="form1" action="#">

            Email: <input type="text" placeholder="Email" name="email" /> </br></br>

            <input type="submit" name="submit" value="Submit" onclick="validatEmail(document.form1.email)">

        </form>

    </div>


</body>

</html>

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !