Merchant Account Services

Merchant Account Blog

Getting a House Number for AVS

Performing address verification (AVS) is a must for any non-retail business, especially Internet-based merchants. Popular gateways like make performing AVS easy. You only need to send over the customer’s zip code and full street address to perform AVS successfully. However, other less popular and advanced gateway like the LinkPoint API require you to provide it with the house number of a customer’s street address. (e.g. if the street address is 123 Main Street the house number is 123).

AVS works by validating the house number provided by the customer against the house number of the billing address the card issuing bank has on file. However, the house number is not necessarily in the typical format demonstrated above. A PO Box or Rural Route will not have the house number first in the street address.

So how do you get this number from the street address if the number may appear anywhere in the street address? With regular expressions of course! The solution is pretty simple although an explanation of how the regular express works will not be provided (but I will tell you it does provide you with the first set of digits it finds in the street address). The regular expression used will work in any language that support Perl Compatible Regular Expressions (PCRE). The code is written in PHP.

// The street address provided by the customer
$address = "123 Main Street";

// The regular expression that gets the first set of digits in the address
$number = preg_replace('/^.*?(\d+).*$/i', '$1', $address);

// Echo out the house number
echo $number;

Leave a Reply