Solved

Programmatically verify a PO Box?

Posted on 2014-03-25
2
432 Views
Last Modified: 2014-03-25
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
Comment
Question by:DrDamnit
2 Comments
 
LVL 8

Assisted Solution

by:soupBoy
soupBoy earned 100 total points
ID: 39954152
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
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 400 total points
ID: 39954158
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now