js에서 정규 일치하는 메일박스

2335 단어
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="  http://www.itbool.com" />
</head>
    <body>
<form action="">
<p> :<input type="text" name="user"/></p>
<p>Email:<input type="text" name="email"/></p>
<p><input type="submit" /></p>
</form>
    </body>
    <script>
     document.getElementsByTagName('form')[0].onsubmit=function (){
     //  ,part.test() 
     var part=/^[a-zA-Z0-9]{6,11}$/;
     if(!part.test(document.getElementsByName('user')[0].value)){
     alert(" ");
     return false;
     }
     var partt=/^\w+@\w+(\.\w+)+$/;
     if(!partt.test(document.getElementsByName('email')[0].value)){
     alert(" emial");
     return false;
     }
     
     }
    </script>
</html>

메일박스 정보의 빨간색을 선택하십시오.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
    <body>
        <input type="submit" value=" " onclick="find()" />
        <ul>
            <li> &lt;[email protected]&gt;</li>
            <li> 15732113942</li>
            <li> &lt;[email protected]&gt;</li>
        </ul>
    </body>
    <script>
    function find(){
        var lis=document.getElementsByTagName('li');
        var patt=/\w+@\w+(\.\w+)+/;
        var i=0;
        for (var i = 0; i < lis.length; i++) {
            if(patt.exec(lis[i].innerHTML)!=null){
                lis[i].style.background="red";
            }
        }
    }
    </script>
</html>

좋은 웹페이지 즐겨찾기