我在用户提供的地址字段上使用Laravel regex validation。
我发现了多个有助于验证address字符串为有效posts (如here或here )的帖子,但我需要做相反的工作,并确保提供的字符串不是posts。
PS我不需要做任何的地址验证,只是想确保它除了一个邮箱。
我发现这条规则非常有用,因为它检查的是po方框号。
/^\s*(.*((p|post)[-.\s]*(o|off|office)[-.\s]*(b|box|bin)[-.\s]*)|.*((p|post)[-.\s]*(o|off|office)[-.\s]*)|.*((p|post)[-.\s]*(b|box|bin)[-.\s]*)|(box|bin)[-.\s]*)(#|n|num|number)?\s*\d+/i有人能帮我为这个或任何类似的词创建相反的表达式吗?
我怀疑我必须使用负前瞻性?!
发布于 2018-10-19 17:35:22
使用regex negative lookahead ?!进行求解
/^(?!.*(?:(.*((p|post)[-.\s]*(o|off|office)[-.\s]*(box|bin)[-.\s]*)|.*((p |post)[-.\s]*(box|bin)[-.\s]*)))).*$/i此规则不要求必须有邮箱号。
这些都将成为过去的例子:
"The Postal Road",
"Box Hill",
"123 Some Street",
"Controller's Office",
"pollo St.",
"123 box canyon rd",
"777 Post Oak Blvd",
"PSC 477 Box 396",
"RR 1 Box 1020",
"Coop services",
"65 Brook Ave Ste 1P",
"pacific city",
"orange county",
"obox",
"pbox",
"party house",
"p shorty",
"something pacif pobo",
"po helpkline box",
"po ferrirs",
"panther boxing",
"box center",
"post office",
"Post",
"porceline"这些都不能通过验证。
"post office box",
"POBOX",
"po box",
"POBox12234",
"p o box",
"P.O.Box",
"HC73 P.O. Box 217",
"P O Box125",
"P. O. Box",
"P.O. Box 123",
"P.O. Box",
"PO Box N",
"PO Box",
"PO-Box",
"POBOX123",
"Po Box",
"Post Box 123",
"Post Office Box 123",
"Post Office Box",
"p box",
"p-o box",
"p-o-box",
"p.o box",
"p.o. box",
"p.o.-box",
"po box 123",
"po box",
"po-box",
"pobox",
"pobox123",https://stackoverflow.com/questions/52880617
复制相似问题