码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript 检查 email 地址的正则表达式

时间:2014-07-24 21:22:46      阅读:347      评论:0      收藏:0      [点我收藏+]

标签:style   http   java   color   io   width   for   re   

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>

JavaScript 检查 email 地址的正则表达式,布布扣,bubuko.com

JavaScript 检查 email 地址的正则表达式

标签:style   http   java   color   io   width   for   re   

原文地址:http://www.cnblogs.com/xkzy/p/3865785.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!