javascript 正则 验证 第25节
<html> <head> <title>Form对象</title> <script type="text/javascript"> function $(id) { return document.getElementById(id); } function checkPhone(num) { var reg = new RegExp("^1[358]\\d{9}$","gi"); //[0-9] ^[a-z][a-f]$ //var reg = /^1[358]\d{9}$/gi; alert(reg.test(num)); } var s = "i like java you like Iava"; //var r = new RegExp("java","gi"); var r = /i/gi; alert(s.replace(r,"*")); </script> </head> <body > <div>正则对象</div> 1.</br> <form action="事件.htm" method="GET" name="form1" > <table border="1" width="500px" cellpadding="5" cellspacing="0" align="left"> <tr> <th colspan="2">注册表</th> </tr> <tr> <td align="right">姓名:</td> <td><input type="text" name="username" /></td> </tr> <tr> <td align="right">手机号码:</td><td><input type="text" id="num" onblur="checkPhone(this.value)"/></td> </tr> </table> </form> </body> </html>
rs: