以下功能,为什么不报警触发检查有效的电子邮件地址失败
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test('[email protected]')){
alert('Please make sure the email is valid.');
}
以下功能,为什么不报警触发检查有效的电子邮件地址失败
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test('[email protected]')){
alert('Please make sure the email is valid.');
}
使用。
function IsValidEmail(emailText) {
var atpos = emailText.indexOf("@");
var dotpos = emailText.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= emailText.length) {
return false;
}
return true;
}
因为你的逻辑倒 - 你警告,如果事情是一个有效的电子邮件地址。
if (valid email address) { alert }
和[email protected]
不是有效的电子邮件地址。没有警报。
尝试!
反转测试的结果:
if (! /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test('[email protected]')) {
alert('Please make sure the email is valid.');
}
您可以使用此一个。 [点] 2,3字符作为 每个域后,将支持
var email_filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (email_filter.test('[email protected]')) {
alert('Email is valid');
}
你知道HTML5有输入类型的电子邮件? – madalinivascu
@madalinivascu是的,我愿意。 –
为什么不使用它? – madalinivascu