Android判断11位手机号码的方法(正则表达式)
作者:沈文泽 时间:2022-03-06 03:17:43
项目里头需要做一个判断用户输入的号码是否是正确的手机号码,正确的手机号码应该是11位的,这里我们需要用一个正则表达式来进行判断,正则表达式的定义如下:
public final static String PHONE_PATTERN = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
然后我们写一个方法,主要有两个参数,1、正则表达式;2、输入的字符串(号码),方法如下:
/**
* 正则表达式匹配判断
* @param patternStr 匹配规则
* @param input 需要做匹配操作的字符串
* @return true if matched, else false
*/
public static boolean isMatchered(String patternStr, CharSequence input) {
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(input);
if (matcher.find()) {
return true;
}
return false;
}
以上方法可以直接使用。
手机号码判断的,就这么简单就解决了网站的支持!
来源:http://blog.csdn.net/qq_16628781/article/details/53484348
标签:android,判断,号码
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Unity实战之FlyPin(见缝插针)小游戏的实现
2022-05-21 19:46:31
![](https://img.aspxhome.com/file/2023/1/69201_0s.jpg)
SpringBoot如何优雅的整合Swagger Api自动生成文档
2022-08-10 00:49:29
![](https://img.aspxhome.com/file/2023/3/72343_0s.png)
Java 数据结构与算法系列精讲之贪心算法
2023-09-12 17:56:13
![](https://img.aspxhome.com/file/2023/3/65303_0s.jpg)
Android开发实现控件双击事件的监听接口封装类
2023-02-15 00:56:18
浅谈JVM内存溢出原因和解决思路
2023-11-23 12:24:15
![](https://img.aspxhome.com/file/2023/1/59781_0s.jpg)
SpringBoot用配置影响Bean加载@ConditionalOnProperty
2022-11-28 22:16:07
![](https://img.aspxhome.com/file/2023/2/75482_0s.jpg)
流式图表拒绝增删改查之kafka核心消费逻辑上篇
2023-04-19 03:32:11
hibernate4基本配置方式详解
2023-03-11 11:07:43
![](https://img.aspxhome.com/file/2023/7/68737_0s.png)
基于C#实现的端口扫描器实例代码
2022-04-29 20:21:56
解决IDEA克隆代码后在右下角没有git分支的问题
2021-11-23 09:43:19
![](https://img.aspxhome.com/file/2023/2/63112_0s.jpg)
Android开发之资源文件用法实例总结
2023-05-13 06:02:39
Java实现快速排序过程分析
2023-07-27 18:40:57
Android 开发之BottomBar+ViewPager+Fragment实现炫酷的底部导航效果
2022-01-07 19:39:20
![](https://img.aspxhome.com/file/2023/6/96786_0s.gif)
了解Java虚拟机JVM的基本结构及JVM的内存溢出方式
2023-02-20 03:08:51
![](https://img.aspxhome.com/file/2023/8/63288_0s.png)
android studio2.3如何编译动态库的过程详解
2023-07-11 03:47:48
Java通过反射将 Excel 解析成对象集合实例
2023-05-22 18:49:02
![](https://img.aspxhome.com/file/2023/2/69942_0s.jpg)
SpringCloud灾难性雪崩效应处理方法之降级实现流程详解
2022-03-24 15:31:36
Linux下Hadoop 2.7.3 安装搭建过程
2023-11-08 05:13:59
![](https://img.aspxhome.com/file/2023/0/58870_0s.png)
C#使用CefSharp实现内嵌网页详解
2022-04-12 15:02:00
![](https://img.aspxhome.com/file/2023/0/80110_0s.gif)
JAVA实现的简单万年历代码
2021-10-02 21:35:34