Home  >  Article  >  Web Front-end  >  How to determine whether the email format is correct in js

How to determine whether the email format is correct in js

小云云
小云云Original
2018-03-17 16:17:114280browse

This article mainly shares with you how to use js to determine whether the email format is correct. This article mainly shares it with you in the form of code. I hope it can help you.

<form action="#"onsubmit="return validate_form(this);" method="post">    Email: <input type="text" name="email" size="30">
    <input type="submit" value="Submit">
</form>
<script type="text/javascript">    function validate_required(field,alerttxt)
    {        with (field)
        {            if (value==null||value=="")
            {alert(alerttxt);return false}            else {return true}
        }
    }    function validate_email(field,alerttxt)
    {        with (field)
        {            apos=value.indexOf("@")            dotpos=value.lastIndexOf(".")            if (apos<1||dotpos-apos<2)
            {alert(alerttxt);return false}            else {return true}
        }
    }    function validate_form(thisform)
    {        with (thisform)
        {  if (validate_required(email,"请填入内容!")==false)
            {email.focus();return false}            if (validate_email(email,"请填写正确的邮箱格式!")==false)
            {email.focus();return false}
        }
    }
</script>

Related recommendations:

Verification method for email format in js

php verification email format

JS code to verify whether the email format is correct_javascript skills

The above is the detailed content of How to determine whether the email format is correct in js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn