0151 355 4555

IsValid

Description

Checks a postcode for validity.

The return value includes the following details:

  • ValidPostcode contains a simple boolean value indicating if the postcode is valid or not.
  • FormattedPostcode contains the original postcode in a standardised format if it is valid, or blank if not
  • AlternativePostcodes contains a list of possible other postcodes that could have been intended

The service will attempt to validate the supplied postcode. The postcode can be supplied in any format, so CH2 4NE and ch24ne will both be accepted. If the postcode is valid, a version of the same postcode with standardised formatting will be returned.

Whether or not the supplied postcode is valid, a list of possible alternative postcodes will also be returned. These will be poscodes that could be possible mis-typings of the supplied postcode and could be offered to the user as suggested corrections, especially when the supplied postcode is flagged as invalid.

View all Postcode Verify methods

Code Samples

<!-- Import the Integr8 Ajax API -->
<!-- NOTE: Get your own API key to use in the following script tag from: -->
<!-- http://www.data-8.co.uk/integr8/Admin/Ajax.aspx -->
<script src="https://webservices.data-8.co.uk/Javascript/Loader.ashx?key=your-api-key" type="text/javascript">
</script>

<script type="text/javascript">

function loadIntegr8() {
  // Load the PostcodeVerify Integr8 service
  data8.load('PostcodeVerify');
}

function IsValid(postcode) {
  /// <param name="postcode">string</param>
  var postcodeverify = new data8.postcodeverify();
  
  postcodeverify.isvalid(
    postcode,
    null,
    showIsValidResult
  );
}

function showIsValidResult(result) {
  // Check that the call succeeded, and show the error message if there was a problem.
  if (!result.Status.Success) {
    alert('Error: ' + result.Status.ErrorMessage);
  }
  else {
    // TODO: Process method results here.
    // Results can be extracted from the following fields:
    // result.ValidPostcode
    // result.FormattedPostcode
    // result.AlternativePostcodes
  }
}

loadIntegr8();

</script>