Regular Expression checking for numeric length

regex

Solution

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.

Problem

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.

Original source