Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

validate zip code in javascript

<input type="text" id="zipCode" />

how can i validate that this is a valid zip code in javascript?

like image 673
Scott Avatar asked Feb 19 '26 23:02

Scott


1 Answers

You can match the input against this regex.

/^\d{5}(-\d{4})?(?!-)$/

US zip codes are 5 digits followed by an optional 4 digits.

like image 64
Rocket Hazmat Avatar answered Feb 22 '26 11:02

Rocket Hazmat