Solved

Programmatically verify a PO Box?

Posted on 2014-03-25
2
441 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 109

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

770 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