One Regular Expression to validate US and Canada ZIP / Postal Code

前端 未结 2 2208
小鲜肉
小鲜肉 2021-02-20 17:33

I am developing a stationery program. Customers have choice to pick their region either US or Canada. When they enter address they have to enter ZIP/Postal code. I am trying to

2条回答
  •  猫巷女王i
    2021-02-20 18:05

    Furthering the answer above you could add (?i) to the beginning of the regex to make is case insensitive. So it would look like this:

    ^(?i)(\d{5}(-\d{4})?|[A-CEGHJ-NPRSTVXY]\d[A-CEGHJ-NPRSTV-Z] ?\d[A-CEGHJ-NPRSTV-Z]\d)$
    

提交回复
热议问题