PHP regexp US address

前端 未结 6 1953
忘掉有多难
忘掉有多难 2021-01-12 19:07

I\'m trying to see what would be a good way to validate a US address, I know that there might be not a proper way of doing this, but I\'m going for the basic way: #

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-12 19:30

    This is not a bulletproof solution but the assumption is that an address begins with a numeric for the street number and ends with a zip code which can either be 5 or 9 numbers.

    ([0-9]{1,} [\s\S]*? [0-9]{5}(?:-[0-9]{4})?)

    Like I said, it's not bulletproof, but I've used it with marginal success in the past.

提交回复
热议问题