Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

address validation: can't be a P.O. Box 1

Status
Not open for further replies.

GaryCam

Programmer
Dec 16, 2003
69
0
0
US
I've been testing, studying & Googling but have yet to solve this problem. I'm sure this is a very common validation routine, but I can't find the answer. The user inputs a shipping address and I need to make sure it's a street address and not a P.O. Box. Here's what I have so far:
Code:
var stripped = document.formpmt.shipAdd.value.replace(/\./g,""); [i]//to remove periods[/i]
stripped = stripped.replace(/ /g,"");  [i]//to remove spaces[/i]
stripped = stripped.toLowerCase();
if(!(stripped.match("pobox")=="null")) {
  alert("We can't deliver to a P.O. Box.\n Please provide a street address for shipping.");
  document.formpmt.shipAdd.focus();
return false;
}
As it stands, the alert box is always triggered regardless of the input. Can someone please shed some light?
Thanks in advance,
Gary



 
Remove the word "null" from quotes - null is a value, not a string.

You might also want to add 'bmbox' and 'bcmbox' to that list:


Also consider stripping "\" and "/" as some people write "P/O" or "P\O".

Hope this helps,
Dan




Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
I never write P.O. Box 1234.

I almost always just write or type Box 1234.

Works just as well. Just offering that.
 
Thanks, Dan. Eliminating the quotes around 'null' did the trick. These computers are so picky!

As for the '/' and '\', I will try to incorporate them as well. Thanks for the heads up.

Thank you too, Big Red. I hadn't thought of that.

Best,
Gary
 
[ ]

I always write POB 123 and some people say PO Bx 123 or just Bx 123, none of which are caught by your function. And occasionally, when I worked in the Post Office, I would see "Post Office Box 123" and variations thereof.

mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Steven Raymond
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top