JavaScript Perfect Email Validation

Email Validation

To get JavaScript Perfect Email Validation is a little tricky. So I am going to share this simple solutions with you. Hope this may help and save your time.

JavaScript Code

function validateEmail() {
   // info@coderbd.com
    var email = document.forms["coderbd"]["email"].value;
    var atpos = email.indexOf("@");
    var dotpos = email.lastIndexOf(".");
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {
        alert("Not a valid e-mail address");
        return false;
    }else{    
    alert("Email address is valid");
    }
}

HTML Code


<form name="coderbd" action="#" onsubmit="return validateEmail()" method="post">
Email: <input type="text" name="email">
<input type="submit" value="Send">
</form>

Insert your JavaScript code at script tag and html code at body tag.

Check out Perfect Email validation using JavaScript.

If there is any issue please write a comment. If this post is helpful, please share it in your social media account.

1 thought on “JavaScript Perfect Email Validation

Leave a Reply