Skip to content

Instantly share code, notes, and snippets.

@Xerosigma
Last active August 29, 2015 13:56
Show Gist options
  • Save Xerosigma/8979693 to your computer and use it in GitHub Desktop.
Save Xerosigma/8979693 to your computer and use it in GitHub Desktop.
Regex
// Five or nine digit U.S. zipcodes.
public static final String REGEX_ZIP = "[^\\d{5}([\\-]?\\d{4})?$]";
// Dates: 12/31/2014
public static final String REGEX_DATE = "^(0[1-9]|1[012])[- \\/.](0[1-9]|[12][0-9]|3[01])[- \\/.](19|20)\\d\\d$";
// Dates: 2014/12/31
public static final String REGEX_DATE_DATA = "^(19|20)\\d\\d[- \\/.](0[1-9]|1[012])[- \\/.](0[1-9]|[12][0-9]|3[01])$";
// Integers
public static final String REGEX_INT = "^[0-9]+$";
// Integers or floats with max precision of two.
public static final String REGEX_INT_FLOAT = "^(\d+)?(\.\d{1,2})?$";
// Floats with max precision of two.
public static final String REGEX_FLOAT = "^(\d+)?\.\d{1,2}$";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment