<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns=""> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title>
</head> <body> <form method="post" action="" > 手机:<input type="text" maxLength=11 size=30 onchange="checkform()"/> <br> 邮箱:<input type="text" onchange="checkMail(\'emailBox\')"/> <input type="submit" value="提交" > </form> <script type="text/javascript"> function checkform() { if(document.form1.mobile.value.length!=11) { //验证手机号为11位 alert("您的手机号不正确哦!") document.form1.mobile.focus(); return false; } var mobile=document.form1.mobile.value; var reg0=http://www.likecs.com/^13\d{5,9}$/; //130--139。至少7位 var reg1=http://www.likecs.com/^15\d{5,9}$/; //15至少7位 var reg2=http://www.likecs.com/^18\d{5,9}$/; //18 var my=false; if (reg0.test(mobile))my=true; if (reg1.test(mobile))my=true; if (reg2.test(mobile))my=true; if (!my){ alert("您的手机号不正确哦") document.form1.mobile.focus(); return false; } } </script> <!--<script type="text/javascript"> function checkEmail() { document.getElementById(\'emailBox\').onblur = function(){ var value = this.value; if(typeof value == \'undefined\') { //未定义 alert(\'Email不能为空\'); return false; }else if(value.trim() == \'\') { //空值 alert(\'Email不能为空\'); return false; }else if(value.indexOf(\'@\') == -1) { //不包含@ alert(\'Email必须包含@,如abc@qq.com\'); return false; }else if(value.indexOf(\'.\') == -1) { //不包含. alert(\'Email必须包含.,如abc@qq.com\'); return false; }else { //包含@与. if(value.indexOf(\'@\') == 0 || value.indexOf(\'.\') == 0) { //以@或.开头 @qq.com 和 .@qq.com非法 alert(\'Email只能以字母开头\'); return false; }else if(value.lastIndexOf(\'@\') == value.length-1 || value.lastIndexOf(\'.\') == value.length-1) { //以@或.结束 a@qq.com@ 和a@qq.com.非法 alert(\'Email只能以字母结束\'); return false; }else{ //包含@与.且不以它们结束 var count_at = 0; if(value.indexOf(\'@\') != value.lastIndexOf(\'@\')){ //多个@ a@b@qq.com非法 alert(\'Email只能包含一个@,如abc@qq.com\'); return false; } var beforeAt = value.substr(0,value.indexOf(\'@\')); if(beforeAt.indexOf(\'.\') != -1){ //a.b@qq.com 非法 alert(\'Email的@前必须全部为字母\'); return false; } value = value.replace(\'@\',\'.\'); //删除@,.替换@,反正替换后按.分隔时a@.拼接,导致@.之间无法判定为空 var splits = value.split(\'.\'); //按.分隔 var a_z = \'abcdefghijklmnopqrstuvwxyz\'; //仅字母 for(var i in splits){ //对点分隔后的字符进行单字切割并匹配a-z if(splits[i] == \'\'){ alert(\'Email的@.或..不能连接\'); return false; } var words = splits[i].split(""); //单字切割 for(var w in words){ //对每个单字进行验证 if(a_z.indexOf(words[w].toLowerCase()) == -1) { alert(\'Email只能包含字母!\'); return false; } } } } } return true; } } </script>--> <script type="text/javascript"> function checkMail(str){ var strReg=""; var r; var strText=document.all(str).value; //strReg=http://www.likecs.com/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/i; strReg=http://www.likecs.com/^\w+((-\w+)|(\.\w+))*\@{1}\w+\.{1}\w{2,4}(\.{0,1}\w{2}){0,1}/ig; r=strText.search(strReg); if(r==-1) { alert("邮箱格式错误!"); document.all(str).focus(); } } </script> </body> </html>