Instantly share code, notes, and snippets.

Embed
What would you like to do?
Australian Postcode to state conversion
function returnState(postcode) {
var postcode = parseInt(postcode, 10);
if ((postcode >= 1000 && postcode <=1999) || (postcode >= 2000 && postcode <= 2599) || (postcode >=2619 && postcode <= 2899) || (postcode >= 2921 && postcode <= 2999)){
return 'NSW';
} else if ((postcode >= 200 && postcode <= 299) || (postcode >= 2600 && postcode <= 2618) || (postcode >= 2900 && postcode <= 2920)) {
return 'ACT';
} else if ((postcode >= 3000 && postcode <= 3999) || (postcode >= 8000 && postcode <= 8999)) {
return 'VIC';
} else if ((postcode >= 4000 && postcode <= 4999) || (postcode >= 9000 && postcode <= 9999)) {
return 'QLD';
} else if ((postcode >= 5000 && postcode <= 5799) || (postcode >= 5800 && postcode <= 5999)) {
return 'SA';
} else if ((postcode >= 6000 && postcode <= 6797) || (postcode >= 6800 && postcode <= 6999)) {
return 'WA';
} else if ((postcode >= 7000 && postcode <= 7799) || (postcode >= 7800 && postcode <=7999)) {
return 'TAS';
} else if ((postcode >= 800 && postcode <= 899) || (postcode >= 900 && postcode <= 999)) {
return 'NT';
}
return '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment