在上面的代码中,我们提供了一个示例手机号码13812345678进行测试。 5. 输出验证结果 运行代码后,会输出验证结果。对于示例手机号码13812345678,输出将是: text 13812345678 是有效的手机号码。 通过上述步骤,你可以在Java中使用正则表达式来验证手机号码的格式。
importjava.util.regex.Matcher;importjava.util.regex.Pattern;publicclassPhoneNumberValidator{// 手机号码正则表达式privatestaticfinalStringPHONE_REGEX="^1[3-9][0-9]{9}$";// 验证手机号码的方法publicstaticbooleanisValidPhoneNumber(StringphoneNumber){Patternpattern=Pattern.compile(PHONE_REGEX);Matchermatche...
验证手机号 我国的手机号一般是以1开头,后面跟着10位数字。因此,可以用如下正则表达式: publicstaticbooleanisValidPhoneNumber(StringphoneNumber) {Stringregex ="^1[3-9]\\d{9}$";// 适用于中国手机号returnphoneNumber.matches(regex); } 验证电话号码 ...
一个手机号的格式为:1、前3位必须为131,150,183,151,137等等;2、必须是11位;3、必须都是数字。 判断一个手机号是否合法,就会有很多的判断语句,将会特别麻烦,这时候就需要正则表达式了。 一、字符串的匹配 String类中有一个Boolean matches(String regex) 方法,用于判断字符串是否合法。用法如下: public class ...
* 座机号码 * pr#387@Gitee */ public static final String TEL = "(010|02\\d|0[3-9]\\d{2})-?(\\d{6,8})"; 2.直接复制完整代码运行 import java.util.regex.Pattern; public class Test { /** * 移动电话 * eg: 中国大陆: +86 180 4953 1399,2位区域码标示+11位数字 * 中国...
Java使⽤正则表达式验证⼿机号和电话号码的⽅法⼀个朋友需要,所以写了这两个,话不多说,看代码 中国电信号段 133、149、153、173、177、180、181、189、199 中国联通号段 130、131、132、145、155、156、166、175、176、185、186 中国移动号段 134(0-8)、135、136、137、138、139、147、150、151...
最新、最全、最准确的手机号正则表达式 更新到2018年5月,支持最新的166号段 /*** Java 使用*/String PHONE_NUMBER_REG= "^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\\d{8}$"; /** * JS 使用*/"18016381232".match(/^(13[0-9]|14[579]|15[0-3,5-9...
public class PhoneFormatCheckUtils{ public static boolean isMobile(String mobile) { String regex = "^((13[0-9])|(14[0,1,4-9])|(15[0-3,5-9])|(16[2,5,6,7])|(17[0-8])|(18[0-9])|(19[0-3,5-9]))\\d{8}$"; ...
http://www.cnblogs.com/zengxiangzhan/p/phone.html 我的需求还有点特殊,需要验证的不是单个手机号,可能是多个手机号,所以用到了递归, 先上测试结果: 源代码如下: 01publicstaticvoidmain(String[] args)throwsException { 02String mobile1="12345677890"; ...
Pattern p=Pattern.compile("^1[34578]\\d{9}$"); // 改成这样Matcher m=p.matcher("15217855576");System.out.println(m.matches()); // true