JavaScript 检查 email 地址的正则表达式
?1.代码(1)
<html>
<head>
<title>Checking an email address - Version 01</title>
<script type="text/javascript" language="javascript">
<!-- //
function IsMatchingAddress(str){
var myRegExp = /[a-z0-9-]{1,30}@[a-z0-9-]{1,65}.[a-z]{3}/ ;
return myRegExp.test(str)
}
function TestGuess(){
var EmailAddr = "asdf@asdf.net".toLowerCase();
alert(IsMatchingAddress(EmailAddr));
}
// -->
</script>
</head>
<body>
<h3>This page allows you to enter and check
an email address such as asdf@java2s.com.com</h3>
<form>http://www.huiyi8.com/yinxiao/?
<button type="Button" onclick="TestGuess()">
Click here to enter email address</button>
</form>
</body>
</html>
2. [代码]方法2
<html>
<head>
<title>Checking an email address - Version 02</title>
<script type="text/javascript" language="javascript">
<!-- //中国音效网
function IsMatchingAddress(str){
var myRegExp = /[a-z0-9-.]{1,30}@[a-z0-9-]{1,65}.(com|net|org|info|biz|([a-z]{2,3}.[a-z]{2}))/ ;
return myRegExp.test(str)
}
function TestGuess(){
var EmailAddr = "asdf@java2s.com".toLowerCase();
alert(IsMatchingAddress(EmailAddr));
}
// -->
</script>
</head>
<body>
<h3>This page allows you to enter and check an email address
such as asdf@java2s.com,</h3>
<form>
<button type="Button" onclick="TestGuess()">
Click here to enter email address</button>
</form>
</body>
</html>
3. [代码]方法3
?
<html>
<head>
<title>E-mail Example</title>
<script type="text/javascript">
function isValidEmail(sText) {
var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/;
return reEmail.test(sText);
}
function validate() {
var oInput1 = document.getElementById("txt1");
if (isValidEmail(oInput1.value)) {
alert("Valid");
} else {
alert("Invalid!");
}
}
</script>
</head>
<body>
<P>E-mail Address: <input type="text" id="txt1" /><br />
<input type="button" value="Validate" onclick="validate()" /></p>
</body>
</html>
相关文章
- 10-02根据Email地址跳转到相应的邮箱登录页面 (转)
- 10-02用正则表达式判断是不是正确的IP地址的代码
- 10-02sqlserver 镜像配置问题 (针对服务器网络地址 "TCP://XXXXX:5022" 无法访问或不存在。 请检查网络地址名称,并检查本地和远程端点的端口是否正常运行)
- 10-02javascript中常见的函数封装 :判断是否是手机,判断是否是微信,获取url地址?后面的具体参数值,毫秒格式化时间,手机端px、rem尺寸转换等
- 10-02javascript – jQuery:如何检查两个元素是否具有相同的类
- 10-02正则表达式:网页爬虫:从TXT中获取邮箱地址(获取的练习,缺点:一行只能匹配一个)
- 10-02前端笔记之JavaScript(六)让人头疼的正则表达式
- 10-02javascript中常用的一些功能及正则表达式的用法
- 10-02javascript – 正则表达式和ISO8601格式的DateTime
- 10-02JavaScript中的正则表达式(终结篇)