We are allowing US Zip Codes as only (1) 9 digits, or (2) 10 digits with a dash before the last 4 digits.
The following regexp gives a compilation error:
private static final String USZIPCODE_MATCH_FORMAT_REGEXP = "^\d{5}[\\-]?\d{4}$";
Invalid escape sequence
In Java you need to escape the \ as well. So, you need
"^\\d{5}[\\-]?\\d{4}$"
Also, you can specify the hyphen simply as
"^\\d{5}-?\\d{4}$"
The - is not special when used outside [].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With