Android:最新最全的验证正确手机号码的工具类(2017)


最新最全的验证正确手机号码的工具类


文 | 莫若吻     


1.代码如下:


(注:大家可根据自己需要进行适当的修改,不懂或者有问题的地方可留言给我。^_^)

/**
 * 正则表达式工具类
 * 
 * @author 诺诺
 * 
 */
public class RegexUtils {	
	
	public static boolean isBasePhone(String mobile){
		Pattern p1 = Pattern
				.compile("^((13[0-9])|(15[^4,\\D])|(177)|(18[0,5-9]))\\d{8}$");
		Matcher m1 = p1.matcher(mobile);
		return m1.matches();
	}
	
	/**
	 * 验证是否是有效手机号
	 * 条件:
	 * 以+86开头或者是11位有效手机号
	 * 移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188
	 * 联通:130、131、132、152、155、156、185、186
	 * 电信:133、153、180、189、(1349卫通)、177
	 * 
	 * @param mobiles
	 * @return
	 */
	public static boolean isPhoneNum(String mobiles){
		Pattern p2 = Pattern
				.compile("^(\\+?86)\\d{11}$");
		Matcher m = p2.matcher(mobiles);
		
		if(mobiles.length()==11){		
			return isBasePhone(mobiles);
			
		}else if(mobiles.length()>11 && m.matches()){
			String mobile=mobiles.substring(3);		
			return isBasePhone(mobile);
		}	
		return false;
		
	}
	/**
	 * 验证是否是以“+86”开头的手机号码
	 * @return
	 */
	public static boolean isPhonePre(String phoneNum){
		Pattern p2 = Pattern
				.compile("^(\\+?86)\\d{11}$");
		Matcher m = p2.matcher(phoneNum);
		
		if(m.matches()){
			String mobile = phoneNum.substring(3);
			return isBasePhone(mobile);
		}	
		return false;
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值