Javascript Email Validation Form

Check user email address forms to make sure they are valid using JavaScript before saving their info. The JavaScript code is provided here.

The function below checks if the content has the general syntax of an email.

This means that the input data must contain at least an @ sign and a dot (.). Also, the @ must not be the first character of the email address, and the last dot must at least be one character after the @ sign:

<script language="Javascript">
function checksubmit()
{
apos=document.add_data.email.value.indexOf("@")
dotpos=document.add_data.email.value.lastIndexOf(".")
if (document.add_data.email.value == "" || apos<1 || dotpos-apos<2)
{
alert("Please fix: email")
document.add_data.email.focus()
return false
}
return true
}
</script>

You may also like...

8 Responses

  1. J.D. says:

    Excellent idea and implementation!

    Thank you!

  2. virendra says:

    if i insert “@.” in my email field then what happens.
    I found it will validate this email address.
    please give me a proper solution

  3. Blake says:

    function isValidEmail(sText) {
    var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;
    return reEmail.test(sText);
    }

  4. Mattias says:

    Blakes function works, but I noticed that if the string contains a long word after the @-sign, the script uses a lot of processor power. This often causes Firefox (3.5.8) or Internet Explorer (7.0) to crash. Test with this string “jfhskdj@jdhrwueyrroqyweuyrs.s”

  5. This is nice javascript email validation..
    Its easy to using.:-)

    Thanks a lot..!

  6. MCTS Exam says:

    Just came to get a code from here. It is much better than others and pretty compact code compare to other scripts! However, it would have been better if there had few examples how to use them in a code since I am new to HTML and coding 🙂

  7. roopa says:

    Nice and clean codes…:-)

Leave a Reply