0151 355 4555

CleanAddress

Description

Formats, verifies and corrects a given address into a full UK address.

A MatchLevel is also provided, explaining any action taken on supplied address. These are:

  • OK_Unchanged - The address provided has been cleansed successfully and was verified to be correct. No modifications have been made.
  • OK_Corrected - The address provided has been cleansed successfully and was verified to be correct. Modifications have had to be made in order to make the address correct.
  • NOK_Building - The address provided has been cleansed successfully however it was only found to be correct to a building level.
  • NOK_Street - The address provided has been cleansed successfully however it was only found to be correct to a street level.
  • NOK_Town - The address provided has been cleansed successfully however it was only found to be correct to a town level.
  • NOK_NoMatch - The address provided has been cleansed successfully however a match could not be found within the UK.

Non-UK addresses are also handled and produce a MatchLevel of NOK_Foreign. The following options control how international addresses are handled:

  • DefaultCountryCode - an ISO 2 character code for the country to assume the address is in unless otherwise specified. This defaults to GB.
  • DetectCountry - set to true to attempt to automatically detect the country from the provided address information, possibly overriding the default country
  • Country - if DetectCountry is set to true, this is taken as additional user input alongside the address to influence the country detection function. The format of this is not enforced, so could be provided as "US", "USA" or "United States"
  • IncludeCountry - includes the CountryISO2 field in the raw address result and the CountryName field in the main part of the result

View all Postcoder (contact us for more information about this service) 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 Postcoder Integr8 service
  data8.load('Postcoder');
}

function CleanAddress(address) {
  /// <param name="address">data8.address. Set up the Lines properties before calling this method.</param>
  var postcoder = new data8.postcoder();
  
  postcoder.cleanaddress(
    address,
    null,
    showCleanAddressResult
  );
}

function showCleanAddressResult(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.Result
    //   Contains the formatted version of the requested address in the Address field,
    //   and a structured version of the address in the RawAddress field.
    // result.MatchLevel
    //   Contains a MatchLevel to indicate how well the address matched to PAF. Possible values are OK_Unchanged, OK_Corrected, NOK_Building, NOK_Street, NOK_Town, NOK_NoMatch
    // result.CountryName
    //   Contains the name of the country the address is in.
  }
}

loadIntegr8();

</script>