Home  >  Article  >  Backend Development  >  Regular expression method for mobile phone number verification

Regular expression method for mobile phone number verification

小云云
小云云Original
2018-03-19 10:25:051698browse

本文和主要介绍了Android 2018最新手机号验证正则表达式方法,需要的朋友可以参考下,希望能帮助到大家。


/** 
* 判断字符串是否符合手机号码格式 
* 移动号段: 134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,184,187,188 
* 联通号段: 130,131,132,145,155,156,170,171,175,176,185,186 
* 电信号段: 133,149,153,170,173,177,180,181,189 
* @param str 
* @return 待检测的字符串 
*/


public static boolean isMobileNO(String mobileNums) { 
  /** 
   * 判断字符串是否符合手机号码格式 
   * 移动号段: 134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,184,187,188 
   * 联通号段: 130,131,132,145,155,156,170,171,175,176,185,186 
   * 电信号段: 133,149,153,170,173,177,180,181,189 
   * @param str 
   * @return 待检测的字符串 
   */ 
  String telRegex = "^((13[0-9])|(14[5,7,9])|(15[^4])|(18[0-9])|(17[0,1,3,5,6,7,8]))\\d{8}$";// "[1]"代表第1位为数字1,"[358]"代表第二位可以为3、5、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。 
  if (TextUtils.isEmpty(mobileNums)) 
    return false; 
  else 
    return mobileNums.matches(telRegex); 
}

”^((13[0-9])|(14[5,7,9])|(15[^4])|(18[0-9])|(17[0,1,3,5,6,7,8]))\d{8}$”这句话其实很简单:

①130-139这十个前三位已经全部开通,后面8位每一位都是0-9之间的任意数;

②14开头的目前只有145、147、149三位,后面8位每一位都是0-9之间的任意数;

③15开头的除了154以外第三位可以随意取,后面8位每一位都是0-9之间的任意数;

④180-189这十个前三位已经全部开通,后面8位每一位都是0-9之间的任意数;

⑤17开头的目前有170、171、173、175、176、177、178这七位,后面8位每一位都是0-9之间的任意数;

这些正则表达式只是在前端进行判断,实际开发里面这些数据依旧会传给后台,后台会在数据库里去判断这11位号码是不是手机号,我们这样写是为了过滤一些最基本的号码,保证输入的号码位数是11位,还有就是一些看起来就不是手机号的某些11位数。

相关推荐:

php中手机号验证实例用法汇总

The above is the detailed content of Regular expression method for mobile phone number verification. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn