下面的函数可以对Email地址格式进行检查,只有形如:
[email protected],[email protected]和[email protected]状的串才能通过检查,
如下面这些非法地址都通不过:
@[email protected],[email protected],[email protected].,abc@163@net等等都能剔除出来。
邮件地址就这几种格式吧?比如:
[email protected],[email protected],[email protected]
还有没有更长的?
1<script language="JavaScript1.2">
2function checkmail(mail)
3var strr;
4re=/(\w+@\w+\\.\w+)(\\.{0,1}\w*)(\\.{0,1}\w*)/i;
5re.exec(mail);
6if (RegExp.$3!=""&&RegExp.$3!="."&&RegExp.$2!=".") strr=RegExp.$1+RegExp.$2+RegExp.$3
7else
8if (RegExp.$2!=""&&RegExp.$2!=".") strr=RegExp.$1+RegExp.$2
9else strr=RegExp.$1
10if (strr!=mail) {alert("请填写正确的邮件地址;return false}
11return true;
12}
13</script>