邮箱验证-正则表达式

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

<script type="text/javascript" >
 function chkEmail(){
    var email=document.getElementById('email').value;
    var obj=document.getElementById('showMess');
    var pattern=/^[a-zA-Z]\w+[@]\w+[.][\w.]+$/;
    if(pattern.test(email)){
        obj.innerText="正确";
     obj.style.color='green';
    }else{
        obj.innerText="错误";
     obj.style.color='red';
    }
 }
</script>
</head>
<body>
    <lable>电子邮件:</lable><input type="text" id="email" onblur="chkEmail()"/>
 <span id="showMess"> </span>
  
</body>
</html>

posted @ 2014-02-20 13:25  birdlow  阅读(315)  评论(0)    收藏  举报