Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Disable PO. BOX POST in addresss field

    Hello all,

    I have a home address field, and not allow user enter PO, BOX, POST, P O something like this in address field. Is there any way i can prevent user from entering PO BOX. I want them to enter regular address only (12345 Fox ave.)

    Thanks.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,020
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    function noboxnumber(addressline) {
    var tmpStr = addressline.value.toLowerCase();
    if ((/po\b/.test(tmpStr)) || ((/post\b/.test(tmpStr)) || ((/p\so\b/.test(tpmStr)) || ((/p\.o\b.test(tmpStr)) || ((/box\b/.test(tmpStr))) {
    alert ("Sorry - you must enter a full mailing address, not a PO box number")
    addressline.value="";
    addressline.focus();
    return false;
    }
    }


    This tests for
    PO P O P.O POST BOX (ignoring case) at a word boundary,
    so Pony Road, Boxhill Drive, Longpost Road etc. should be OK
    Last edited by Philip M; 10-09-2003 at 08:00 AM.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,020
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Here is a better version:

    <SCRIPT>
    function noboxnumber(addressline) {
    var tmpStr = addressline.value.toLowerCase();
    tmpStr = "x" + tmpStr;
    if ((/po\b/.test(tmpStr)) || (/p\.o\b/.test(tmpStr)) || (/\s|xpost\b/.test(tmpStr)) || (/\s|xbox\b/.test(tmpStr))) {
    alert ("Sorry - you must enter a full mailing address, not a PO box number");
    addressline.value="";
    return false;
    }
    }
    </SCRIPT>

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Philip.

    i will try it out.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,020
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    In fact what is wanted is to detect the character string box followed by zero or more possible space(s) followed by a digit.

    So the following simplified version should do the trick.

    <SCRIPT>
    function noboxnumber(addressline) {
    if (/box\s*\d/i.test(addressline.value)) {
    alert ("Sorry - you must enter a full mailing address, not a PO box number");
    addressline.value="";
    addressline.focus();
    return false;
    }
    }
    </SCRIPT>

    This overcomes difficulties with addresses such as Finger Post Farm, Salt Box Road and so forth.
    Last edited by Philip M; 10-09-2003 at 06:31 PM.

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Philip,

    i have this code

    Code:
    <html>
    <head>
    <script type="text/javascript">
    <!--
    function isAddress(strValue){
         var objRegExp = /^\d{1,}\s{1}[a-zA-Z]{1,}\s{1}[a-zA-Z]{1,}\.?$/;
         return objRegExp.test(strValue);
    }
    function val(fObj){
         if(!isAddress(fObj.t1.value)){
              alert("Not A Address");
              return false;
         }
         return true;
    }
    // -->
    </script>
    </head>
    <body>
    <form name="form1" method="post" action="" onsubmit="return val(this);"> 
    <input type="text" name="t1">
    <input type="submit" name="Submit" value="Submit">
    </form>
    </body>
    </html>
    it works pretty well, but for some reason is not take a address:

    112 west market street

    it's only take 112 market street

    would you please take a look? thanks

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,020
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Your regular expression requires the input to be in the form

    one or more digits

    followed by a space(s) followed by
    one or more characters

    followed by a space(s) followed by
    one or more characters.

    So 112 West Street meets the test but
    112 West Market Street does not.

    Nor does 112 Grangeway (one word road name only).

    What about "Finger Post Farm, Salt Box Road"? Not all
    residences have numbers.

    In my view you should not try to validate an address in this way. It is sure to go wrong, and reject perfectly proper ones. Many foreign countries have the house number after the street name, not before it. Why lose customers who cannot enter their addresses because of some arbitrary checking code?

    What is it exactly you are trying to achieve? And why do you want that?

    You said you wanted to not accept PO box numbers. Fair enough but I have shown you how to do that. Again, precisely why do you wish to turn away PO Box number addresses?

    I think you should let the user enter his address as he wants it. He is the one who knows best what his address is. If he gets it wrong (say types 123 instead of 132) then there is no way you can detect that. It is his responsibility to get it right, not yours.

    It is OK to validate zip codes or phone numbers for FORMAT (but they can still be entered wrongly), but again you should avoid making these things a condition of submitting the form, as that will cut out many foreign customers.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •