Home > Article > Web Front-end > How to determine whether the email format is correct in js
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
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!