P.O. Box Validation -- Hans?...Steve(Guru)?

Discussion in 'ASP .Net' started by Simple Simon, Nov 9, 2003.

  1. Simple Simon

    Simple Simon Guest

    Hi,
    I need some help getting this P.O. Box regular expression to work, or
    a new expression entirely. I got this one from a Google Groups
    search. It seems to work at: http://regexlib.com/ but not at runtime.

    I need to check if a P.O. Box exists in an address text box...UPS
    won't ship some items to a P.O. Box.

    ValidationExpression="(?i)^((?<!P\.?\s?O\.?\sBox).)+(?<!P\.?\s?O\.?\sBox)$"

    Please help?

    TIA,
    ~Gordon
     
    Simple Simon, Nov 9, 2003
    #1
    1. Advertisements

  2. Simple Simon

    Brian W Guest

    Actually, I think you will find that UPS won't ship _ANYTHING_ to a P.O. Box

    Keep in mind also, as you suggest this is valid:

    P O Box 123

    but so are these:

    P.O. Box 123
    PO Box 123
    P O Box 123
    Box 123
    #123

    (I'm sure I missed some combinations)

    You will have to check for each one as may vary from person to person.

    In addition UPS may ship to:

    132 Main Street
    Box 123
    Anytown, USA

    as it may be a Mailbox Etc. (now UPS Store) store

    Just some extra food for thought


    Good luck
    Brian W
     
    Brian W, Nov 9, 2003
    #2
    1. Advertisements

  3. Simple Simon

    Simple Simon Guest

    Thanks for the cautions Brian, you got a regular expression for that?
    :p

    ~Gordon
     
    Simple Simon, Nov 10, 2003
    #3
  4. Simple Simon

    Vishnu Sistla

    Joined:
    Oct 9, 2011
    Messages:
    1
    Likes Received:
    0
    This Java method should work.
    /**
    * The below are the possible combinations P.O.BOX, PO.BOX, P O BOX, P O B O
    * X, POBOX, PO BOX, P.O.B.O.X
    *
    * @param input
    * @return true if the input value = pobox else false
    */
    public static boolean checkPoBox(String input) {
    boolean poBox = false;
    String inputVal = input;
    try {
    if (input.length() > 4) {
    inputVal = inputVal.replace(".", "").replace(" ", "")
    .toLowerCase();
    if (inputVal.contains("pobox")
    || inputVal.equalsIgnoreCase("pobox")) {
    poBox = true;
    }
    }
    } catch (Exception e) {
    log.debug("Exception from checkPoBox");
    }
    return poBox;
    }
     
    Vishnu Sistla, Oct 9, 2011
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.