Created
January 21, 2012 04:25
-
-
Save mpurbo/1651282 to your computer and use it in GitHub Desktop.
Regular expression for format commonly used in Japanese phone number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final String SPACE = "[\\s\u3000]"; | |
public static final String NUMBER = "[0-9\uff10-\uff19]"; // 0-90-9 | |
public static final String HYPHEN = "[-\uff0d\u2212]"; | |
public static final String NOT_NUMBER_OR_HYPHEN = "[^" + NUMBER.substring(1, NUMBER.length()-1) + HYPHEN.substring(1); | |
public static final String SEPARATOR = "[\\(\\)" + HYPHEN.substring(1, HYPHEN.length()-1) + "]"; | |
public static final String REGEX_PHONEFAX = | |
"(?:" + NOT_NUMBER_OR_HYPHEN + "|^)" + | |
SPACE + "*(" + NUMBER + "{2,4})" + | |
SPACE + "*" + SEPARATOR + | |
SPACE + "*(" + NUMBER + "{2,4})" + | |
SPACE + "*[" + SEPARATOR.substring(3) + | |
SPACE + "*(" + NUMBER + "{2,4})(?:" + | |
NOT_NUMBER_OR_HYPHEN + "|$)"; | |
public static final Pattern PATTERN_PHONEFAX = Pattern.compile(REGEX_PHONEFAX); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment