Created
May 23, 2017 16:46
-
-
Save kimek/b59617bd04fafad160f8ed8448919af3 to your computer and use it in GitHub Desktop.
Get first postcode part from UK postcode with vanilla javascript
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 postcodePart($postcode) { //https://www.mrs.org.uk/pdf/postcodeformat.pdf | |
var $postcodePart; | |
switch($postcode.length) { | |
case 5: | |
$postcodePart = $postcode.substr(0,2) | |
break; | |
case 6: | |
$postcodePart = $postcode.substr(0,3) | |
break; | |
case 7: | |
$postcodePart = $postcode.substr(0,4) | |
break; | |
default: | |
$postcodePart = $postcode; | |
break; | |
} | |
return $postcodePart; | |
} |
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 postcodePart($postcode) { //https://www.mrs.org.uk/pdf/postcodeformat.pdf | |
var $postcodePart; | |
switch($postcode.length) { | |
case 5: | |
$postcodePart = $postcode.substr(0,2) | |
break; | |
case 6: | |
$postcodePart = $postcode.substr(0,3) | |
break; | |
case 7: | |
$postcodePart = $postcode.substr(0,4) | |
break; | |
default: | |
$postcodePart = $postcode; | |
break; | |
} | |
return $postcodePart; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment