且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么是最终的邮政编码和 zip 正则表达式?

更新时间:2023-02-21 19:39:01

没有.

世界各地的邮政/邮政编码并不遵循共同的模式.在某些国家,它们由数字组成,在其他国家,它们可以是数字和字母的组合,有些可以包含空格,有些可以包含点,字符数可以从两个到至少六个不等...

Postal/zip codes around the world don't follow a common pattern. In some countries they are made up by numbers, in others they can be combinations of numbers an letters, some can contain spaces, others dots, the number of characters can vary from two to at least six...

你可以做的(理论上)是为世界上每个国家/地区创建一个单独的正则表达式,而不是推荐的 IMO.但是您仍然会遗漏验证部分:邮政编码 12345 可能存在,但 12346 不存在,也许 12344 也不存在.你如何用正则表达式检查?

What you could do (theoretically) is create a seperate regex for every country in the world, not recommendable IMO. But you would still be missing on the validation part: Zip code 12345 may exist, but 12346 not, maybe 12344 doesn't exist either. How do you check for that with a regex?

你不能.