<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="得到数字" onclick="checkMobile(btn_getNum.value);"/> </body> </html>
html5实现 input必须为手机号且非空的验证方法
最新推荐文章于 2025-11-15 17:57:15 发布
本文介绍了一个使用JavaScript实现的简单验证手机号格式的功能,并通过点击按钮获取并验证手机号。主要涉及了正则表达式用于验证手机号格式的有效性。
2328

被折叠的 条评论
为什么被折叠?



