Solved

Programmatically verify a PO Box?

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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:
The viewer will learn how to count occurrences of each item in an array.

747 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

9 Experts available now in Live!

Get 1:1 Help Now