I allow my users to enter their address all on one single line, or sometimes in multiple lines but not separated into address, city, state, zip fields. I need to be able to parse out the valid address data and then perform address validation. How can I do that with your LiveAddress API?

asked 09 Feb, 13:05

Questions's gravatar image

Questions ♦♦
40182318
accept rate: 15%

edited 09 Feb, 16:51


Absolutely. Extracting a valid address from a freeform address string is easy and only requires a few additional address variations. Let's dive right into how to use our LiveAddress API to perform Single Line Address Processing.

The minimum requirement to verify an address through our system is address and ZIP code. This is sent to our system in two fields:

street - This is the street level address data including suite and apartment numbers. Basically everything that is not city/state/zip. This must always have a minimum of two components.

Box 100" is acceptable.  "Box" is never acceptable.

lastline - This is the city/state/zip code data. Lastline must always contain either a ZIP code or two components.

City|ZIP, State|ZIP, City|State, ZIP, are all acceptable.  City by itself or State by itself is never acceptable.

We will assume that the street data portion comes first and that the lastline data comes last. Let's look at the following example address:

3214 North University Ave #409 Provo UT 84604

Begin by creating the first permutation (or address variation) by breaking the string into two fields: street and lastline, working from right to left. The permutations can be generated on the fly, as needed, or in a batch before submitting to our API.

On-the-fly: Generate the first permutation and submit. If the address fails, generate the next and try again. Repeat until a successful address is matched or there are no more permutations to try. If the address is a positive match, stop there.

Batch: Generate and serialize all the possible permutation from the input data. Submit them to our API in sequence, stopping with the first positive match or if they all fail.

Here are the permutations from the example address:

P1: 3214 North University Ave #409 Provo UT  |  84604
P2: 3214 North University Ave #409 Provo  |  UT 84604
P3: 3214 North University Ave #409  |  Provo UT 84604
P4: 3214 North University Ave  |  #409 Provo UT 84604
P5: 3214 North University  |  Ave #409 Provo UT 84604
P6: 3214 North  |  University Ave #409 Provo UT 84604

Since the street field must have at least two components to it there is no need to test further.

Here are the results:

P1: 3214 North University Ave #409 Provo UT  |  84604  -->  Fails address validation  
P2: 3214 North University Ave #409 Provo  |  UT 84604  -->  Fails address validation  
P3: 3214 North University Ave #409  |  Provo UT 84604  -->  Valid delivery point  
P4: 3214 North University Ave  |  #409 Provo UT 84604  -->  Valid delivery point, but without secondary number  
P5: 3214 North University  |  Ave #409 Provo UT 84604  -->  Valid delivery point, we added the "Ave" to make it deliverable  
P6: 3214 North  |  University Ave #409 Provo UT 84604  -->  Fails address validation

In the case of the example address, it only took three permutations to get a positive match for the address. That's pretty fast. The positive match with the most data will usually be the most correct answer. If you were to continue testing you would get two more passing results but they would have less address data than the first positive match. for example, the address 3214 North University is deliverable but no longer has the unit number attached to it. So, for best results, stop with the first positive match.

The end result is that you allow your users to enter addresses in the way that is most convenient for them and you can still parse out valid delivery data and get it back from our system broken down into address component data.

NOTE: While this is a very effective method, it should always be used in conjunction with user interaction to verify the results. Sometimes it even makes your service look more impressive if you are able to give multiple results (for increased accuracy). If using this method with our LIveAddress for Lists service, you will want to use the address that validates with the most amount of data in the "street" field. This will give you the best results.

link

answered 09 Feb, 13:28

Jeffrey%20-%20SmartyStreets's gravatar image

Jeffrey - SmartyStreets ♦♦
2.2k14
accept rate: 50%

edited 12 Mar, 11:54

Since the LiveAddress API has been upgraded to support 100 addresses at once, you can now perform this operation in a single HTTP request. And with our new pricing, it comes at no extra expense to you. In other words, for the permutations that don't verify, you don't pay for them. You only buy the good, verifiable addresses.

Update: PHP example of performing verification on a single-line address -- demonstrates submitting each permutation in the same batch so only a single request is performed.

Update: Here's a rudimentary example of performing single-line address processing (SLAP) with jQuery. This has a few quirks because of JSONP limitations, but it's basically functional. Here's the fiddle for it where you can try it out right away.

link

answered 27 Mar, 09:24

Matt%20-%20SmartyStreets's gravatar image

Matt - SmartyStreets
413
accept rate: 33%

edited 15 May, 12:31

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×47
×11
×1

Asked: 09 Feb, 13:05

Seen: 296 times

Last updated: 15 May, 12:31