<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>IE</title> <script language="javascript" type="text/javascript"> function checkMobile(str) { if(str==""){ alert("手机号不能为空!"); } else{ var re = /^1\d{10}$/ 以1开始后面加10位数字 if (re.test(str)) { alert("正确"); } else { alert("手机号格式错误!"); } } } </script> </head> <body> <input type="text" id="btn_getNum"/> <input type="button" value="得到数字" οnclick="checkMobile(btn_getNum.value);"/> </body> </html>
html5实现 input必须为手机号且非空的验证方法
最新推荐文章于 2023-01-16 10:15:33 发布