<!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> <pre> 1:用户名只能字母及数字6-11位 2:email为正确的email </pre> <form action=""> <p>用户名:<input type="text" name="username" /></p> <p>邮箱:<input type="text" name="email" /></p> <p><input type='submit' value='提交'/></p> </form> </body> <script> document.getElementsByTagName('form')[0].onsubmit = function(){ var patt =/^[a-zA-Z0-9]{6,11}$/ ; if(!patt.test(document.getElementsByName('username')[0].value)){ alert('用户名由字母及数字6-11位'); return false; } patt=/^\w+@\w+(\.\w+)+$/ ; if(!patt.test(document.getElementsByName('email')[0].value)){ alert('请输入正确的email'); return false; } } </script> </html>

我的微信
这是我的微信扫一扫