Hi I have been asked to validate postal/zip codes against the countries like Netherland, United Kingdom, Spain, Italy, Belgium etc. Can anyone suggest that how can I do it programmatically using perl script or javascript preferablly. Thanks.
how are you displaying this data? will it be part of a form to select from? if this is the case, you will have to become acquainted with manipulating form element values as well as comparing them. as an example, if you have one dropdown select that displays countries, and another for the zip codes, you could make it that either when they select countries only those zipcodes will be displayed in the zipcode selection or you could make it that if they type in a certain zipcode, it automatically selects the corrects country, another solution i can think of is to have a drop down select for countries and a textbox to type in the zipcode, then use javascript event handlers - onchange, onblur, - to pass that txtboxes information to a javascript function. what this function will do is check the input against the country selected, you will have to have an array of predefined zips and countries to work with, if the content doesnt match up, you can give the user some friendly help message, those are a couple of ways, otherwise what you can do is allow the user to submit the form and check the information that has been posted and run that through a function, and if it is not correct send the person back to the form to reenter info. but i think the primary thing here is to have predefined arrays of data to work with, or even better a database table to call, and check against, php and mysql will help there. is this what you are asking or is it something else?
Hii thanks for the reply. See right now what I have is a user registration web page. For selecting the country there is a drop down list consisiting of 15 different countries like Netherland, Spain, Italy, Belgium, United Kingdom, Norway, France etc. To enter the postal code there is a textbox. I have to check that for the country selected, the postal code should be valid. I want to do it without using any predefined hashes or array. Or I want a perl module/perl script/java script where in I get all the regular expressions in one place.
To build software like this, I've always had to create a postal codes table which maps postal codes to their various countries, states, etc. I buy this data can be bought for the United states, canada, and mexico for about $100 and it comes in a zip file quarterly that I load into my system. I'm not sure about the UK though. In any case, once you get a table storing all the valid data, then your registration page just needs the validation logic built into it. You can do it on the submit of the registration, check the data, and then if invalid send them back to the registration page with the error section in red. One method I've been using in the last few years is to use some AJAX though. When the user types in the zipcode, you can automatically go lookup the country associated with it and then populate it without the user leaving the page. I have been using JQuery to simplify my AJAX work recently. I hope that helps!