Regex for C/O in address line

谁说胖子不能爱 提交于 2019-12-13 04:41:26

问题


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'.

回答1:


This matches all of your given inputs:

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



回答2:


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?



来源:https://stackoverflow.com/questions/19505835/regex-for-c-o-in-address-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!