asp.netregexstreet-address

Best Strategies for preventing addresses with PO Boxes?


I have a client which is shipping via UPS, and therefore cannot deliver to Post Office boxes. I would like to be able to validate customer address fields in order to prevent them from entering addresses which include a PO box. It would be best if this were implemented as a regex so that I could use a client-side regex validation control (ASP.NET).

I realize there's probably no way to get a 100% detection rate, I'm just looking for something that will work most of the time.


Solution

  • This should get you started. Test to see if the Address field matches this regex.

    "^P\.?\s?O\.?\sB[Oo][Xx]."
    

    Translation to English: That's a P at the beginning of the line, followed by an optional period and space, followed by an O, followed by an optional period, followed by a space, followed by "Box", followed by anything else.