电子邮件表单验证-确保它只有一个'@'符号 [英] Email Form Validation - Ensuring it only has one '@' symbol
本文介绍了电子邮件表单验证-确保它只有一个'@'符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试验证表单,以确保输入的电子邮件地址值格式正确.除了检查它仅包含一个'@'符号外,我一切正常.到目前为止,这是我的代码
I am trying to validate a form to ensure that the entered email address value is in the correct format. I have everything working except checking that it only contains one '@' symbol. This is my code so far
var x = document.forms["registration"]["email"].value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos< 1 || dotpos<atpos+2 || dotpos+2>=x.length) {
alert("Not a valid e-mail address");
return false;
推荐答案
检查并验证单个'@'.下面提到的一个是使用的标准电子邮件正则表达式:
To check and validate for single '@'. The below mentioned one is the standard Email Regex which is been used:
\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
这篇关于电子邮件表单验证-确保它只有一个'@'符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文