用正则表达式鉴别非法手机号
时间: 2023-07-03 11:33:42 浏览: 85
可以使用以下正则表达式来鉴别非法手机号:
```regex
^1[3-9]\d{9}$
```
其中,^ 表示字符串的开头,$ 表示字符串的结尾,1 表示手机号的开头必须是1,[3-9] 表示手机号的第二位必须是3~9中的任意一个数字,\d 表示任意数字,{9} 表示前面的\d必须重复出现9次,即手机号的总位数为11位。如果手机号符合这个正则表达式,则表示它是一个合法的手机号。
相关问题
js正则表达式表单验证手机号
在JavaScript中,可以使用正则表达式来验证手机号码。根据提供的引用内容,有几个示例正则表达式可以用来验证手机号码的合法性。
引用中给出了一个示例代码,使用了正则表达式`/^([0-9]|[\-]) $/g`来判断一个输入量是否为电话号码。这个正则表达式的具体含义可能有误,因为它只能匹配一个数字或连字符(-)。
引用中的示例代码使用了正则表达式`/^(0|86|17951)?(1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/***
引用中的示例代码也展示了使用正则表达式来验证手机号码的方法。示例代码中的正则表达式为`/^[3,4,5,***可以使用正则表达式`/^(0|86|17951)?(1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/`或`/^[3,4,5,6,7,8,9][0-9]{9}$/`来进行JavaScript正则表达式表单验证手机号码的操作。
java正则表达式手机号 java正则表达式手机号
可以使用以下正则表达式来验证手机号码:
```java
String phoneNumber = "12345678901"; // 要验证的手机号
// 定义手机号正则表达式
String regex = "^(?:(?:\\+|00)86)?1[3-9]\\d{9}$";
// 创建 Pattern 对象
Pattern pattern = Pattern.compile(regex);
// 创建 Matcher 对象
Matcher matcher = pattern.matcher(phoneNumber);
// 判断手机号是否匹配正则表达式
if (matcher.matches()) {
System.out.println("手机号格式正确");
} else {
System.out.println("手机号格式错误");
}
```
***
相关推荐
![json](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)