Domanda

I'm trying to write a regex to detect any c/o patterns in my address line.
I want my regex to detect patterns like Care Of, c/o, c.o., CareOf, etc.

I've done PO Box, email address validations, etc. in the past, but this is new to me.
I'm not very strong in this area and am still trying at my end, but any help would be greatly appreciated.

Thanks much.


Adding further detail to my question:

-> I'm attempting this in Java (through a server side call) and Javascript (through a client side call).
-> I'm doing this for address validation; we want to make sure that the customer doesn't add Care Of addresses (similar to PO Box validation)

I need to parse through Address Line 1 and Address Line 2 (text boxes) values in my page and show an error message if any of them contains a 'Care Of' value.
Possible inputs: 'Care Of John', 'c/o John', 'C/O John', 'C.O. John'
Required output: If there is a pattern match, I need to show an error message: 'Sorry, we do not ship to C/O addresses'.
È stato utile?

Soluzione

This matches all of your given inputs:

(?i)c(are|.|/) ?o(\.|f)?

Altri suggerimenti

You should probably just have a single expression with a series of alternations in it:

"Care Of|C\/O|C\.O\.|CareOf"

And set it to case-insensitive.

What language are you working in?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top