Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 543
  • Last Modified:

Programmatically verify a PO Box?

I need a way to disallow / ban a PO box from being entered in on a form. USPS address verification (web services) does not appear to allow this for anyone who is not specifically printing a label.

What services (if any) are available to do this? (Free / pay all OK).
0
DrDamnit
Asked:
DrDamnit
2 Solutions
 
soupBoyCommented:
Here is a jsfiddle that uses regex to find a p.o. box

Here is the code code that I put in the fiddle...
HTML:
<input type="text" id="address1" name="address1" />
<input type="submit" value="Validate" />

<div class="result">
    <!-- result goes here -->
</div>

Open in new window

Javascript:
var pattern = new RegExp('[PO.]*\\s?B(ox)?.*\\d+', 'i');

$('[type="submit"]').on('click', function(e){
    e.preventDefault();
    var pattern = new RegExp('[PO.]*\\s?B(ox)?.*\\d+', 'i');
    var result = pattern.test($('#address1').val());
    var displayText = (result) ? 'Might be a PO Box' : 'Doesn\'t appear to be a PO Box';
    
    $('.result').text(displayText);
});

Open in new window


I have built a number of shopping carts in the past and I have struggled with P.O. Boxes and addresses in general.  I was surprised to see all of the various and crazy addresses people have in the United States (or what seemed crazy to me at least...).

In the end, I added as much validation as I could to stop the majority of the uses from entering PO Boxes or other restrictions I had in place.  I also added some text in the cart  saying something along the lines of 'We Cannot Ship to P.O. Boxes'.  

Hopefully this helps!

[Resources I used to help answer this]:
Programmatically verify a PO Box (Stackoverflow)
0
 
Ray PaseurCommented:
I haven't tested this, but it looks reasonably good.  Scan this page for 5 Dec 2013
http://www.zen-cart.com/showthread.php?193601-PO-Box-Ban-1-4-support-thread
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now