admin 管理员组文章数量: 888526
Android 手机号格式验证(正则)
这是一个简易版本的,只验证位数和前两位
//判断输入的格式是否为手机号public boolean isPhone(String phone){String regex="^1[3456789]\\d{9}$";if (phone.length()!=11){Log.i(TAG, "isPhone: 手机位数不对");return false;}else {Pattern p=Pattern.compile(regex);Matcher m=p.matcher(phone);boolean isMatch=m.matches();Log.i(TAG, "isPhone: 是否正则匹配"+isMatch);return isMatch;}}
还有一个详细版本的请看
public static boolean isPhone(String phone) {String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";if (phone.length() != 11) {MToast.showToast("手机号应为11位数");return false;} else {Pattern p = Pattern.compile(regex);Matcher m = p.matcher(phone);boolean isMatch = m.matches();Log.i(TAG, "isPhone: 是否正则匹配"+isMatch);return isMatch;}
}
再附上密码格式验证(正则)
常用正则表达式大全
本文标签: Android 手机号格式验证(正则)
版权声明:本文标题:Android 手机号格式验证(正则) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1686636670h20183.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论