Code Snippets

  

JavaScript Source Code


Welcome to Dream.In.Code
Become an Expert!

Join 148,616 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,283 people online right now. Registration is fast and FREE... Join Now!





Validate Zip Code

Validates a zip code based on both US zip code schemes: 12345-1234 or 12345

Submitted By: skyhawk133
Actions:
Rating:
Views: 19,031

Language: JavaScript

Last Modified: February 28, 2005
Instructions: Call using isZip(form.field.value);

Returns boolean

Snippet


  1. function isZip(s)
  2. {
  3.  
  4.      // Check for correct zip code
  5.      reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
  6.  
  7.      if (!reZip.test(s)) {
  8.           alert("Zip Code Is Not Valid");
  9.           return false;
  10.      }
  11.  
  12. return true;
  13. }

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.




Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month