PHP regexp US address

前端 未结 6 1908
忘掉有多难
忘掉有多难 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:26

    I agree with salman: have user enter the data in different fields (one for zip, one for state, one for city, and one for the #/street name. Use a different regex for each field. For the street #/name the best expression i came up with was

    /^[0-9]{1,7} [a-zA-z0-9]{2,35}\a*/
    

提交回复
热议问题