Phone number verification tools

package util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class PhoneFormatCheckUtils {

/ **
* Number mainland or Hong Kong can number
* /
public static boolean isPhoneLegal (String str) throws PatternSyntaxException {
return isChinaPhoneLegal (str) || isHKPhoneLegal (str);
}

/ **
* China mobile phone number 11 digits, matching format : + top three fixed format after any number 8
* this process, the top three formats:
* 13+ arbitrary number
* 15 + 4 addition any number of
* 18 + 1 and an arbitrary number in addition to the 4
* 17 + 9 except the arbitrary number
* 147
* /
public static Boolean isChinaPhoneLegal (String STR) throws the PatternSyntaxException {
String regExp = "^ ((13 is [0-9]) | (15 [^. 4]) | (18 is [0,2, 3, 5-9]) | (. 17 [0-8]) | (147)). 8 \\ {D} $ ";
the Pattern of Pattern.compile P = (regExp);
Matcher m = p.matcher (STR);
return m .matches ();
}

/ **
* 8-digit phone number in Hong Kong, 5 | 6 | 8 | +7 place any number beginning 9
* /
public static boolean isHKPhoneLegal (String str) throws PatternSyntaxException {
String regExp = "^ (5 | 6 | 8 | 9) \\ }. 7 {$ D ";
the Pattern of Pattern.compile P = (regExp);
Matcher m = p.matcher (STR);
return m.matches ();
}

}

Guess you like

Origin www.cnblogs.com/lijun6/p/11710837.html