Skip to content

Instantly share code, notes, and snippets.

@mrmascott10
Last active June 30, 2022 15:33
Show Gist options
  • Save mrmascott10/314b7497e1fbe1f72f13d2cc5f373d7e to your computer and use it in GitHub Desktop.
Save mrmascott10/314b7497e1fbe1f72f13d2cc5f373d7e to your computer and use it in GitHub Desktop.
Validate a postcode without using a database.
<script>
// ****************************************
// Checks if a postcode is valid
// ****************************************
function postcodeValid(postcode) {
var result;
$.get( "https://api.postcodes.io/postcodes/" + postcode + "/validate", function(data) {
result = data['result'];
});
return result;
}
// ****************************************
// ****************************************
// * Get details about a postcode
// ****************************************
function postcodeValid(postcode) {
var result;
$.get( "https://api.postcodes.io/postcodes/" + postcode, function(data) {
result = data;
});
return result;
}
// ****************************************
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment