SmartFreight® Addressing API

 

Our javascript library allows you to validate address fields on your website.

Our library is stand-alone and does not require any other javascript libraries (for example we do not require JQuery, or AngularJS).


Auto Complete Sample


Before you begin: You must Register for a unique API Key. If you do not have an API Key Click here to register

The validateAddress method

        void smartfreight.validateAddress(
           JSObject address,
           DOMString region,
           DOMString apikey,
           optional Function addressValidatedCallback
        );
        
Parameter Type Description
address JSObject A JSObject containing all of the applicable lines of address. See the address object parameter for details.
region DOMString The region/country to filter the auto complete. Please see the FAQ for a list of valid regions.
apikey DOMString Your unique API key obtained by registering on this website. If you have not registered; click here to register
addressSelectedCallback optional Function This function is called when the validation has completed. A validation response object is returned with a property indicating whether the address is valid. See the validation response object for details.

The addess object parameter

Parameter Type Description
name DOMString The business name at this address (where available)
add1 DOMString The first street line of the address
add2 DOMString The second street line of the address
add3 DOMString The Town/Suburb/City of the address (depending on region)
add4 DOMString? The State/County/Province of the address (depending on region)
add5 DOMString? The Postcode of the address (depending on region)
add6 DOMString The Country of the address (depending on region)
type DOMString? The type of address selected (DA: Delivery Area, PO: Post Office Box) (depending on region)


The validation response object parameter

Parameter Type Description
valid boolean true: the address was valid, false: the address failed validation

 


Including the Validation in your Web page
To enable the auto complete on an input element with in your web page follow these simple steps:
1) Include our javascript library in your html

        <!-- Latest and minified JS -->
        <script src="//api.ifsconnect.net/addressing/client-min-latest.js"></script>
        

2) Declare a function which will be called when the validation is complete.
3) On an element action event within the document, call the smartfreight.validateAddress method.

        
        // set the address fields to variables
        var deliveryname = document.getElementById('deliveryname');
        var addressline1 = document.getElementById('addressline1');
        var addressline2 = document.getElementById('addressline2');
        var addressline3 = document.getElementById('addressline3');
        var addressline4 = document.getElementById('addressline4');
        var addressline5 = document.getElementById('addressline5');

        // Some constants
        var region = 'AUSTRALIA';
        var sfapikey = 'testing123';

        // Declare the callback
        function addressValidated(o) {
            if (o.valid) {
                document.getElementById('addressvalidinfo').innerHTML = '<img src="greentick.png">Your address is valid';
            } else {
                document.getElementById('addressvalidinfo').innerHTML = '<img src="redcross.png">Your address is not valid. Please try again';
            }
        }

        // Perform validation on an event
        addressline3.onblur = function() {
        
            // Create the address object
            var address = { add3: addressline3.value,
                add4: addressline4.value,
                add5: addressline5.value
            };
        
            // Call the validation function
            smartfreight.validateAddress(address, region, sfapikey, addressValidated);
        };
        

Try it out
We have uploaded some samples to jsfiddle.net

Try the following examples:

Location Sample Description
Australia http://jsfiddle.net/smartfreight/UQzz7/ Validates the Suburb / State and Postcode

 FAQ - Frequently Asked Questions

Posted on: 04/07/2017