Posted By

devstori on 01/18/15


Tagged

code jquery zip


Versions (?)

jQuery: Check if the zip code is in an array of zips


 / Published in: jQuery
 

Check if the user input zip code is in an array.

  1. //Check Zip in Array:
  2. <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
  3. <script>
  4. var zipCodeArray = ["85069", "85021", "85260", "85022"];
  5. $(function() {
  6. $("#zip").live('keyup', function(){
  7. var zip = $(this).val();
  8. if(zip.length >4){
  9. if($.inArray(zip, zipCodeArray) > -1){
  10. //do nothing, or do whatever you want
  11. //we have a return true here.
  12. }else{
  13. alert("Sorry, we only offer services in certain areas at this time.");
  14. }
  15. }
  16. });
  17. });
  18. </script>

Report this snippet  

You need to login to post a comment.