...

View Full Version : Disable PO. BOX POST in addresss field



petertran123
10-08-2003, 07:59 PM
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.

Philip M
10-09-2003, 08:48 AM
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

Philip M
10-09-2003, 12:31 PM
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>

petertran123
10-09-2003, 02:36 PM
Thanks Philip.

i will try it out. :thumbsup:

Philip M
10-09-2003, 03:29 PM
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.

petertran123
10-14-2003, 04:15 PM
Thanks Philip,

i have this 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

Philip M
10-14-2003, 07:55 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum