Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4006316
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:30:01+00:00 2026-05-20T08:30:01+00:00

Looking to validate PO Box but wanted to know if such validation existed. I

  • 0

Looking to validate PO Box but wanted to know if such validation existed. I have the Address field split into Address 1 and Address 2 (Where such PO, Apt, Suite info would go)

Example:

Address 1: 123 Main Street
Address 2: Suite 100
City: Any Town      
State: Any State
Zip: Any Zip

PO Box (Can sub BIN for BOX as well) Examples:

  • PO Box 123
  • P.O. Box 123
  • PO 123
  • Post Office Box 123
  • P.O 123
  • Box 123
  • 123

  • 123
  • POB 123
  • P.O.B 123
  • P.O.B. 123
  • Post 123
  • Post Box 123

(I know there are probably more I need to validate for but this is what I could think of, feel free to add or correct)

I know a RegEx would be best for this and I’ve seen the other questions on Stack #1, #2

Using the RegEx from the other question I get good results but it misses some I think it should catch

$arr = array (
    'PO Box 123',
    'P.O. Box 123',
    'PO 123',
    'Post Office Box 123',
    'P.O 123',
    'Box 123',
    '#123',         // no match
    '123',          // no match
    'POB 123',
    'P.O.B 123',    // no match
    'P.O.B. 123',   // no match
    'Post 123',     // no match
    'Post Box 123'  // no match
);

foreach($arr as $po) {
    if(preg_match("/^\s*((P(OST)?.?\s*O(FF(ICE)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", $po)) {
        echo "A match was found: $po\n";
    } else {
        echo "A match was not found: |$po| \n";
    }
}

Why is it not catching the last two values in the array?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:30:01+00:00Added an answer on May 20, 2026 at 8:30 am

    As of now with your regex, the ‘O’ in ‘OFFICE’ is required. Try ^\s*((P(OST)?.?\s*(O(FF(ICE)?))?.?\s+(B(IN|OX))?)|B(IN|OX)) instead (grouping the ‘O’ in a conditional match).

    EDIT: That should be /^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i instead. BTW, http://rubular.com/ is a pretty good regular expression testing engine. Always nice to know of new tools 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a RegEx for validating email addresses, but I'm really looking to validate
I don't know the first thing about Informatica but I am looking for ways
I'm looking for an annotation-based validation framework, that would allow me to validate parameter
I'm trying to remote validate a field by looking at two different fields. The
I'm looking to validate a (hidden) tag, which is nothing but some javascript, in
I'm looking for something that will validate the following: 13175551234 3175551234 but NOT validate:
I have been looking into creating a signature on the OAuth site & over
I'm looking for a way to validate the SQL schema on a production DB
I'm looking for a regex that will allow me to validate whether or not
I'm looking for a plugin for jQuery that can validate as a key is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.