Useful Javascript Post Office Box Regex Pattern

We work with a variety of clients that have all customer of all sorts of demographics. I find that older clientele seem to try to “game” the system from time to time.

A prime example is the one below. With the following regex check. I had to not only check for PO Box and all it’s various permutations. But I also needed to check to see if the user input “PO ###” as well.

Below is an example of the pattern used. You can also find the regex pattern shared on regexr.com (http://regexr.com/39d4l)

<script>
// <![CDATA[
var pattern = /\b(?:p\.?\s*o\.?|post\s+office)(\s+)?(?:box|[0-9]*)?\b/i;
// ]]>
</script>

Aaron Ware

Over the past decade Aaron Ware has worked with leading brands, start-ups and everyone in between to develop innovative, highly interactive, feature-rich websites and online apps.

| @aaronware