代码拉取完成,页面将自动刷新
package com.te.datalake.util;
import java.util.concurrent.ThreadLocalRandom;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 号码验证工具类 段炼
*/
public class PhoneNumberUtils {
/**
* 中国移动拥有号码段为:139,138,137,136,135,134,159,158,157(3G),151,150,188(3G),187(3G
* );13个号段 中国联通拥有号码段为:130,131,132,156(3G),186(3G),185(3G);6个号段
* 中国电信拥有号码段为:133,153,189(3G),180(3G);4个号码段
*/
private static String mRegMobileStr = "^1(([3][456789])|([5][01789])|([8][78]))[0-9]{8}$";
private static String mRegMobile3GStr = "^((157)|(18[78]))[0-9]{8}$";
private static String mRegUnicomStr = "^1(([3][012])|([5][6])|([8][56]))[0-9]{8}$";
private static String mRegUnicom3GStr = "^((156)|(18[56]))[0-9]{8}$";
private static String mRegTelecomStr = "^1(([3][3])|([5][3])|([8][09]))[0-9]{8}$";
private static String mRegTelocom3GStr = "^(18[09])[0-9]{8}$";
private static String mRegPhoneString = "^(?:13\\d|15\\d)\\d{5}(\\d{3}|\\*{3})$";
private String mobile = "";
private int facilitatorType = 0;
private boolean isLawful = false;
private boolean is3G = false;
public PhoneNumberUtils(String mobile) {
this.setMobile(mobile);
}
public void setMobile(String mobile) {
if (mobile == null) {
return;
}
/** */
/** 第一步判断中国移动 */
if (mobile.matches(PhoneNumberUtils.mRegMobileStr)) {
this.mobile = mobile;
this.setFacilitatorType(0);
this.setLawful(true);
if (mobile.matches(PhoneNumberUtils.mRegMobile3GStr)) {
this.setIs3G(true);
}
}
/** */
/** 第二步判断中国联通 */
else if (mobile.matches(PhoneNumberUtils.mRegUnicomStr)) {
this.mobile = mobile;
this.setFacilitatorType(1);
this.setLawful(true);
if (mobile.matches(PhoneNumberUtils.mRegUnicom3GStr)) {
this.setIs3G(true);
}
}
/** */
/** 第三步判断中国电信 */
else if (mobile.matches(PhoneNumberUtils.mRegTelecomStr)) {
this.mobile = mobile;
this.setFacilitatorType(2);
this.setLawful(true);
if (mobile.matches(PhoneNumberUtils.mRegTelocom3GStr)) {
this.setIs3G(true);
}
}
/** */
/** 第四步判断座机 */
if (mobile.matches(PhoneNumberUtils.mRegPhoneString)) {
this.mobile = mobile;
this.setFacilitatorType(0);
this.setLawful(true);
if (mobile.matches(PhoneNumberUtils.mRegMobile3GStr)) {
this.setIs3G(true);
}
}
}
public String getMobile() {
return mobile;
}
public int getFacilitatorType() {
return facilitatorType;
}
/**
* 手机号是否合法
*/
public boolean isLawful() {
return isLawful;
}
/**
* 是否是3G
*/
public boolean isIs3G() {
return is3G;
}
/**
* 判断email格式是否正确
*
* @param email
* @return 是否正确
*/
public static boolean isEmail(String email) {
String str = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
Pattern p = Pattern.compile(str);
Matcher m = p.matcher(email);
return m.matches();
}
private void setFacilitatorType(int facilitatorType) {
this.facilitatorType = facilitatorType;
}
private void setLawful(boolean isLawful) {
this.isLawful = isLawful;
}
private void setIs3G(boolean is3G) {
this.is3G = is3G;
}
public static String generatePhoneNumber(){
ThreadLocalRandom current = ThreadLocalRandom.current();
int head3Num = current.nextInt(130, 189);
int tail8Num = current.nextInt(99999999);
String tail8Nums=reform(tail8Num);
String cadidate = head3Num + tail8Nums;
PhoneNumberUtils phoneNumberUtils = new PhoneNumberUtils(cadidate);
if (phoneNumberUtils.isLawful)
return cadidate;
else
return generatePhoneNumber();
}
private static String reform(int tail8Num) {
String s = tail8Num + "";
while (s.length()<8){
s="0"+s;
}
return s;
}
public static void main(String[] args) {
for (int i=0;i<100;++i){
System.out.println(PhoneNumberUtils.generatePhoneNumber());
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。