Created
July 24, 2018 11:01
-
-
Save slav123/668964c1d4b96b7b35335c9e7cc8148d to your computer and use it in GitHub Desktop.
Australian Postcode to state conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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