Skip to content

Instantly share code, notes, and snippets.

@mpurbo
Created January 21, 2012 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpurbo/1651282 to your computer and use it in GitHub Desktop.
Save mpurbo/1651282 to your computer and use it in GitHub Desktop.
Regular expression for format commonly used in Japanese phone number
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