我刚学JS基础验证,搜到邮箱验证最简单的就一句,不懂,求详解
最简单的就一句:
if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test('email'))
{
alert('email不正确');
}
最简单的就一句:
if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test('email'))
{
alert('email不正确');
}
/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test('email') -- 这个正则有个test方法 匹配邮箱字符中('email')这个你不能这么写 ‘email’变成验证这五个字符了 根本不是邮箱地址字符串 。
这个表达式返回一个bool值 最前的"!"号表示取反 true就为false ,false就为true如果 验证失败 !取反后 为true ,if条件成立。。然后弹出 'email不正确'
if(!(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/).test(document.getElementById("email").value)){
alert("邮箱格式不正确!");
}