Regexp way to detect PO Boxes?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • laredotornado

    Regexp way to detect PO Boxes?

    Hi,

    Does anyone have code that detects if a field has been entered in PO
    Box format? I'm trying to prevent users from entering PO Boxes for
    shipping addresses.

    Thanks, - Dave
  • Evertjan.

    #2
    Re: Regexp way to detect PO Boxes?

    laredotornado wrote on 24 apr 2008 in comp.lang.javas cript:
    Does anyone have code that detects if a field has been entered in PO
    Box format? I'm trying to prevent users from entering PO Boxes for
    shipping addresses.
    What country, what format?

    If you ca give a reasonable definition of what is a PO-box string and what
    is not, a regex test should be possible.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • laredotornado

      #3
      Re: Regexp way to detect PO Boxes?

      On Apr 24, 3:01 pm, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
      laredotornado wrote on 24 apr 2008 in comp.lang.javas cript:
      >
      Does anyone have code that detects if a field has been entered in PO
      Box format?  I'm trying to prevent users from entering PO Boxes for
      shipping addresses.
      >
      What country, what format?
      >
      If you ca give a reasonable definition of what is a PO-box string and what
      is not, a regex test should be possible.
      >
      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)
      The country is the United States. My understanding of a PO Box is
      that it is of the form PO Box #### where "#" is a number between 0 and
      9. But the number of numbers could be unlimited, I suppose and there
      could be variation in how "PO Box" is written, e.g. if punctuations
      are included somewhere within. - Dave

      Comment

      • Paul Lautman

        #4
        Re: Regexp way to detect PO Boxes?

        laredotornado wrote:
        On Apr 24, 3:01 pm, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
        >laredotornad o wrote on 24 apr 2008 in comp.lang.javas cript:
        >>
        Does anyone have code that detects if a field has been entered in
        PO Box format? I'm trying to prevent users from entering PO Boxes
        for shipping addresses.
        >>
        >What country, what format?
        >>
        >If you ca give a reasonable definition of what is a PO-box string
        >and what is not, a regex test should be possible.
        >>
        >--
        >Evertjan.
        >The Netherlands.
        >(Please change the x'es to dots in my emailaddress)
        >
        The country is the United States. My understanding of a PO Box is
        that it is of the form PO Box #### where "#" is a number between 0 and
        9. But the number of numbers could be unlimited, I suppose and there
        could be variation in how "PO Box" is written, e.g. if punctuations
        are included somewhere within. - Dave
        Very simplistically the regex
        /PO\s+Box\s+\d+/i
        will work.

        Try it out like this:
        <script type="text/javascript">
        <!--
        var f = /PO\s+Box\s+\d+/i;
        var q = 'Po Box 33';
        alert(f.test(q) );
        // -->
        </script>


        Comment

        • Evertjan.

          #5
          Re: Regexp way to detect PO Boxes?

          laredotornado wrote on 24 apr 2008 in comp.lang.javas cript:
          On Apr 24, 3:01 pm, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
          >laredotornad o wrote on 24 apr 2008 in comp.lang.javas cript:
          >>
          Does anyone have code that detects if a field has been entered in
          PO Box format?  I'm trying to prevent users from entering PO Boxes
          for shipping addresses.
          >>
          >What country, what format?
          >>
          >If you ca give a reasonable definition of what is a PO-box string and
          >what
          >
          >is not, a regex test should be possible.
          >>
          >--
          >Evertjan.
          >The Netherlands.
          >(Please change the x'es to dots in my emailaddress)
          >
          The country is the United States. My understanding of a PO Box is
          that it is of the form PO Box #### where "#" is a number between 0 and
          9. But the number of numbers could be unlimited, I suppose and there
          could be variation in how "PO Box" is written, e.g. if punctuations
          are included somewhere within. - Dave
          t = 'pO box 123';

          if (/^\s*po\s+box\s+ \d+$/i.test(t)) alert('PO box detected');

          --
          Evertjan.
          The Netherlands.
          (Please change the x'es to dots in my emailaddress)

          Comment

          • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

            #6
            Re: Regexp way to detect PO Boxes?

            Paul Lautman escribió:
            Very simplistically the regex
            /PO\s+Box\s+\d+/i
            will work.
            And with optional characters:

            /P\.?O\.?\s+Box\ s+#?\d+/i




            --
            -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
            -- Mi sitio sobre programación web: http://bits.demogracia.com
            -- Mi web de humor al baño María: http://www.demogracia.com
            --

            Comment

            • Evertjan.

              #7
              Re: Regexp way to detect PO Boxes?

              Álvaro G. Vicario wrote on 25 apr 2008 in comp.lang.javas cript:
              Paul Lautman escribió:
              >Very simplistically the regex
              >/PO\s+Box\s+\d+/i
              >will work.
              >
              And with optional characters:
              >
              /P\.?O\.?\s+Box\ s+#?\d+/i
              How right you are,
              don't expand on the OP's definition,
              or there will be no end to this thread.

              --
              Evertjan.
              The Netherlands.
              (Please change the x'es to dots in my emailaddress)

              Comment

              • Michael Wojcik

                #8
                Re: Regexp way to detect PO Boxes?

                laredotornado wrote:
                On Apr 24, 3:01 pm, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
                >laredotornad o wrote on 24 apr 2008 in comp.lang.javas cript:
                >>
                >>Does anyone have code that detects if a field has been entered in PO
                >>Box format? I'm trying to prevent users from entering PO Boxes for
                >>shipping addresses.
                You can ask users not to enter shipping addresses with PO boxes (or,
                more plausibly, only use street addresses for shipping addresses). And
                you can attempt to verify that the addresses they enter do not include
                PO boxes (or are street addresses).

                But you cannot prevent them from entering addresses with PO boxes
                unless you can determine exactly what USPS, or whatever shippers you
                use, will treat as an address with a PO box. And since addresses are
                interpreted by people, that will be difficult.
                The country is the United States. My understanding of a PO Box is
                that it is of the form PO Box #### where "#" is a number between 0 and
                9. But the number of numbers could be unlimited, I suppose and there
                could be variation in how "PO Box" is written, e.g. if punctuations
                are included somewhere within.
                This specification is decidedly incomplete.

                In my experience, USPS, for example, will treat any of the following
                as referring to a PO box:

                PO Box 123
                P.O. box 123
                PO Box #123
                Box 123
                Box no. 123
                #123 [if there's no street address]

                Frankly, if you addressed a letter to:

                Smith
                123
                01945

                and mailed it in the US, and the Marblehead, Massachusetts post office
                (zip code 01945) happened to have a box 123 owned by someone named
                Smith, it would very likely be delivered there.

                Shippers are typically fairly aggressive in deciphering addresses;
                that's good for business.

                So barring getting a strict specification from all of your shippers,
                and implementing it (both unlikely), the best you can do is provide
                some heuristics. My initial suggestion would be: if the first address
                line with a series of digits does not have anything after the digits,
                it's probably a box number.

                That accepts (identifies as a box) any of the examples above, while
                rejecting (identifying as a street address) cases like:

                123 5th [an address on 5th Street]
                123 Main #3 [an address with an apartment number]

                and so forth. Assuming you've already identified the line of text that
                might be a box number, the regex:

                /^\D*\d+$/

                would identify offending entries. (It says: start at the beginning of
                the string and scan until you find a series of digits. Is there
                anything after those digits? If not, then we have a match.)

                My recommendation: if you implement this, and you get a match, alert
                the user that it *appears* they have supplied a PO box, and that PO
                boxes are not allowed, and let them change *or keep* their entry. If
                you get a false positive, you don't want to prevent the user from
                submitting valid data. Better to take invalid input and have a person
                correct it later (by contacting the user or whatever).

                --
                Michael Wojcik

                Comment

                • Dr J R Stockton

                  #9
                  Re: Regexp way to detect PO Boxes?

                  In comp.lang.javas cript message <3854e688-ef70-412d-bae4-fa01f174ae4f@k1
                  3g2000hse.googl egroups.com>, Thu, 24 Apr 2008 12:18:02, laredotornado
                  <laredotornado@ zipmail.compost ed:
                  >Does anyone have code that detects if a field has been entered in PO
                  >Box format? I'm trying to prevent users from entering PO Boxes for
                  >shipping addresses.
                  That sounds like what the Army used to refer to as a thunderbox, for
                  example on the North-West Frontier. WSC was no doubt familiar with the
                  item.

                  Remember when posting here that you are a foreigner. You should,
                  therefore, avoid non-standard local abbreviations and should not assume
                  knowledge of your locally-preferred formats, especially as you don't
                  indicate your location.

                  But we do have still Post Office Boxes here (I think).

                  There's then the question of whether a Post Office Box, or functional
                  equivalent, is necessarily abbreviated to PO Box. I doubt whether that
                  form comes naturally in, say, Russia, France, or PQ. But, if you are an
                  American, you are probably not considering the rest of the world at all,
                  except perhaps Canada.

                  You should probably strip all punctuation from the field first, and any
                  instance of the word "no", and #. Use .replace for that, with a RegExp.


                  --
                  (c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05.
                  Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html-Timo Salmi: Usenet Q&A.
                  Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm: about usage of News.
                  No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.

                  Comment

                  • VK

                    #10
                    Re: Regexp way to detect PO Boxes?

                    On Apr 25, 3:09 pm, Dr J R Stockton <j...@merlyn.de mon.co.ukwrote:
                    Remember when posting here that you are a foreigner.
                    Is c.l.j. under Her Majesty's jurisdiction? I was not aware of it -
                    when did it happen?

                    It is a RegExp question with OP's spelled pattern to seek. If you have
                    nothing productive to say about it, then why polluting the infospace
                    with unrelated crap?

                    To OP: be aware that many services (Mail & More to name one) for extra
                    payment providing P.O. boxes with real mailing addresses, so it will
                    be like "Anytown, Any St. 123, suite #456" with "Anytown, Any St. 123"
                    being the address of the Mail & More office and #456 being your P.O.
                    box cell. This way consider "no P.O." check - either client or server
                    side - as a nice add-on but not a decisive tool for important
                    commercial decisions.

                    Comment

                    • Dr J R Stockton

                      #11
                      Re: Regexp way to detect PO Boxes?

                      In comp.lang.javas cript message <96473fa2-f959-49c6-8467-e2f107524c50@x3
                      5g2000hsb.googl egroups.com>, Fri, 25 Apr 2008 13:51:10, VK
                      <schools_ring@y ahoo.composted:
                      >On Apr 25, 3:09 pm, Dr J R Stockton <j...@merlyn.de mon.co.ukwrote:
                      >Remember when posting here that you are a foreigner.
                      >
                      >Is c.l.j. under Her Majesty's jurisdiction? I was not aware of it -
                      >when did it happen?
                      Typical VK mental inadequacy. Everyone posting here is a foreigner, to
                      at least most of those reading. In practice, everyone except Americans
                      realises that when posting, and writes accordingly. That is one reason
                      why you are liable to be taken as an American yourself.
                      >It is a RegExp question with OP's spelled pattern to seek. If you have
                      >nothing productive to say about it, then why polluting the infospace
                      >with unrelated crap?
                      >
                      >To OP: be aware that many services (Mail & More to name one) for extra
                      >payment providing P.O. boxes with real mailing addresses, so it will
                      >be like "Anytown, Any St. 123, suite #456" with "Anytown, Any St. 123"
                      >being the address of the Mail & More office and #456 being your P.O.
                      >box cell. This way consider "no P.O." check - either client or server
                      >side - as a nice add-on but not a decisive tool for important
                      >commercial decisions.
                      The OP will no doubt, after reading the group, know what value to put on
                      your opinions.


                      Actually, there should be no reasonable objection to having a PO Box
                      included together with a real address; there may be a practical need for
                      a real address, though that is discriminatory against anyone who has no
                      reliable address or who has good reasons not to give it. The correct
                      approach must be to ask for a real, or other sufficient address; and to
                      let the customer subsequently suffer the consequences of getting it
                      wrong.

                      --
                      (c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05.
                      Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html-Timo Salmi: Usenet Q&A.
                      Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm: about usage of News.
                      No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.

                      Comment

                      • VK

                        #12
                        Re: Regexp way to detect PO Boxes?

                        On Apr 26, 6:29 pm, Dr J R Stockton <j...@merlyn.de mon.co.ukwrote:
                        Remember when posting here that you are a foreigner.
                        >
                        Is c.l.j. under Her Majesty's jurisdiction? I was not aware of it -
                        when did it happen?
                        >
                        Typical VK mental inadequacy.
                        Typical Dr. Stockton's fallacy covered by "you cannot speak the
                        language properly". A foreigner:

                        "1. a person not native to the country or jurisdiction under
                        consideration; alien."
                        c.l.j. is not a country - and coming to the jurisdiction, however
                        silly it would be - it is run by NNTP servers all around the globe. So
                        not that I guess.

                        "2. a person from outside one's community."
                        uhm... so outside one's community where P.O. abbreviation is not known
                        and not welcome to discuss: by Dr. Stockton's strong opinion. It is
                        not clear though how did Dr. Stockton determine the nature of the
                        community? Maybe it is right apposite one's community where a person
                        not knowing or pretending do not know what P.O. is, being a dork?

                        Unsurprisingly I understood what you were trying to say: long years
                        of practice of reading your poor English :-)

                        "Remember when posting here that this newsgroup being read by people
                        from different countries where P.O. meaning and functionality may be
                        not known".

                        However silly and paternalistic such comment would be, at least it is
                        closer to the conventional English.

                        Still OP provided the exact search pattern he'd like to have, so even
                        if someone would be misfortune enough do not know what P.O. is, it is
                        completely irrelevant to the problem. The question could be even like
                        "I want to sort out whatchamacallit , for this I have to detect strings
                        like..."
                        In practice, everyone except Americans
                        realises that when posting, and writes accordingly. That is one
                        reason why you are liable to be taken as an American yourself.
                        I am an American but I am not a native English speaker. If I don't
                        understand the matter of some post I simply avoid answering to it. You
                        might accommodate this useful practice as well.
                        Actually, there should be no reasonable objection to having a PO Box
                        included together with a real address
                        FedEx and some other express services do not deliver to P.O. boxes.
                        Mailing insurance cost varies for real addresses and for P.O.

                        Again: why are you trying to talk about matters which are completely
                        alient to you. Do not forget: you are a foreigner.
                        ;-)

                        Comment

                        • Dr J R Stockton

                          #13
                          Re: Regexp way to detect PO Boxes?

                          In comp.lang.javas cript message <b317d5b1-65f1-4a37-a0fc-cd56e18a91a1@l6
                          4g2000hse.googl egroups.com>, Sat, 26 Apr 2008 11:10:03, VK
                          <schools_ring@y ahoo.composted:
                          >I am an American but I am not a native English speaker.
                          Very few of them are; they use a different language but call it the
                          same.
                          If I don't
                          >understand the matter of some post I simply avoid answering to it.
                          That is evidently not a common opinion among your readers here.
                          >Actually, there should be no reasonable objection to having a PO Box
                          >included together with a real address
                          >
                          >FedEx and some other express services do not deliver to P.O. boxes.
                          >Mailing insurance cost varies for real addresses and for P.O.
                          If given a PO Box and a real address, they can deliver to the real
                          address. Also, the OP will be able to omit any such address at the
                          server end.

                          Over-rigorous checking at the client end can easily alienate or stop
                          possible customers. One should reject, at most, only what certainly
                          cannot be handled at the server end.

                          Many Americans consider Canadians, unlike other foreigners, to be so
                          near human as to treat them in the same manner as they treat other
                          Americans; for example, they use the same international dialling code.
                          Therefore, it may well be that the OP would be willing to trade with
                          even the rather strange form of Canadians that are found in Quebec. If
                          so, his processing may need to look for Boite Postale numbers; a
                          francophone might use that term even if it is not nationally standard.

                          --
                          (c) John Stockton, nr London UK. ?@merlyn.demon. co.uk BP7, Delphi 3 & 2006.
                          <URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
                          <URL:http://www.bancoems.co m/CompLangPascalD elphiMisc-MiniFAQ.htmclpd mFAQ;
                          <URL:http://www.borland.com/newsgroups/guide.htmlnews: borland.* Guidelines

                          Comment

                          • Evertjan.

                            #14
                            Re: Regexp way to detect PO Boxes?

                            Dr J R Stockton wrote on 27 apr 2008 in comp.lang.javas cript:
                            If
                            so, his processing may need to look for Boite Postale numbers; a
                            francophone might use that term even if it is not nationally standard.
                            >
                            French is by some convention the international post/mail language.

                            --
                            Evertjan.
                            The Netherlands.
                            (Please change the x'es to dots in my emailaddress)

                            Comment

                            Working...