如何编写一个判断手机号有效性的函数?
- 内容介绍
- 文章标签
- 相关推荐
本文共计73个文字,预计阅读时间需要1分钟。
检测手机号码的简单函数:
javascriptfunction isMobile(mobile) { if (!is_numeric(mobile)) { return false; } return preg_match('/^1[3-9]\d{9}$/', mobile);}
isMobile()function isMobile($mobile) { if (!is_numeric($mobile)) { return false; } return preg_match('#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$#', $mobile) ? true : false; }
本文共计73个文字,预计阅读时间需要1分钟。
检测手机号码的简单函数:
javascriptfunction isMobile(mobile) { if (!is_numeric(mobile)) { return false; } return preg_match('/^1[3-9]\d{9}$/', mobile);}
isMobile()function isMobile($mobile) { if (!is_numeric($mobile)) { return false; } return preg_match('#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$#', $mobile) ? true : false; }

