0

我正在尝试编写一个正则表达式来检测地址行中的任何 c/o 模式。
我希望我的正则表达式能够检测像 Care Of、c/o、co、CareOf 等模式。

我过去做过邮政信箱、电子邮件地址验证等,但这对我来说是新的。
我在这方面不是很强大,我仍在努力,但任何帮助将不胜感激。

非常感谢。


为我的问题添加更多细节:

-> 我正在Java(通过服务器端调用)和Javascript(通过客户端调用)中尝试这个。
-> 我这样做是为了地址验证;我们要确保客户不添加转交地址(类似于邮政信箱验证)

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

2 回答 2

2

这匹配您所有给定的输入:

(?i)c(are|.|/) ?o(\.|f)?
于 2013-10-22T20:49:38.633 回答
0

您可能应该只有一个表达式,其中包含一系列交替:

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

并将其设置为不区分大小写。

你用什么语言工作?

于 2013-10-21T22:23:17.563 回答