用js写一个手机号码验证器
时间: 2024-05-16 11:12:09 浏览: 107
好的,很高兴回答你的问题。以下是一个可能的手机号码验证器的JS代码:
```
function validatePhone(phone) {
let regex = /^1([3-9])\d{9}$/;
return regex.test(phone);
}
```
这段代码使用正则表达式来验证手机号码。如果手机号码匹配正则表达式,即手机号码格式正确,函数会返回true。否则,函数会返回false。
希望这个答案能够帮助到你!
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)