Find file
Fetching contributors…
Cannot retrieve contributors at this time
91 lines (79 sloc) 2.64 KB
<!DOCTYPE html>
<title>Single-Line Address Parsing</title>
<meta charset="UTF-8">
<script src="content/js/jquery.js"></script>
Single-Line Address Parsing (SLAP) Demo
By SmartyStreets
LiveAddress API:
Demo at JsFiddle:
Attempts to parse a single-line (freeform)
address and split into its components. When
the whole address is passed into the
"street" field, LiveAddress will automatically
attempt to parse the pieces of the address
and will usually be able to return valid results.
var js_api_token = 'PUT YOUR HTML IDENTIFIER HERE';
// The base URL of the request (JSONP will be appended later)
var base = '' + js_api_token;
function suppress(event) {
// Used to prevent form submission
if (!event) return false;
if (event.preventDefault) event.preventDefault();
if (event.stopPropagation) event.stopPropagation();
if (event.cancelBubble) event.cancelBubble = true;
return false;
$(function() {
$('#singleLineDemo').submit(function(event) {
var addr = {
street: $('#addr').val()
url: base,
data: addr,
dataType: 'jsonp',
success: function(response) {
if (response.length > 0) {
$('#results').html(JSON.stringify(response, null, ' '));
$('#address').html(response[0].delivery_line_1 + "<br>" + response[0].last_line);
else {
$('#address').html('No valid matches found. Please make sure a city & state OR a zip code was provided with the street address.');
return suppress(event);
body { width: 960px; margin: 50px auto; }
input { font-size: 16px; padding: 5px; }
input[type=text] { width: 75%; }
form { margin-bottom: 2em; }
#address { font: 18px/1.5em sans-serif; }
#results {
margin-top: 3em;
background: #CCC;
text-shadow: 0px 1px 0px white;
white-space: pre;
padding: 10px;
font: 12px/1.5em Monaco, 'Lucida Grande', 'Courier New', serif;
<form id="singleLineDemo">
<input type="text" id="addr">
<input type="submit" value="Perform SLAP">
<div id="address"></div>
<div id="results"></div>