Last active
August 29, 2015 14:04
-
-
Save zapthedingbat/ae973dc47ec112dd2a93 to your computer and use it in GitHub Desktop.
Format a UK postcode to include spaces that may have been omitted.
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 formatPostcode(postcode){ | |
return( | |
//if character fourth from the right is not space | |
postcode.slice(-4,-3) !== " " | |
//insert space three characters from the right | |
?postcode.slice(0,-3) + " " + postcode.slice(-3) | |
//otherwise use origional | |
:postcode | |
) | |
// upper case | |
.toUpperCase(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment