I want to validate a zipcode either 5 digit or 9 digit.
I've written this /^(\d){5|9}$/ but its not matching anything.
But when i give /^(\d){5}$/ its matching properly for 5.
Please help.
Make the last four optional:
^\d{5}(\d{4})?$
Note that I removed the opening/closing slashes as they have nothing whatsoever to do with regex; they are an application language artefact.
The following regex should work.
^(\d{5}|\d{9})$
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