Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Programmatically verify a PO Box?

Posted on 2014-03-25
2
Medium Priority
?
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Assisted Solution

by:soupBoy
soupBoy earned 400 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 111

Accepted Solution

by:
Ray Paseur earned 1600 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

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!

Question has a verified solution.

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

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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

704 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