什么是最终的邮政编码和 zip 正则表达式? [英] What is the ultimate postal code and zip regex?

查看:65
本文介绍了什么是最终的邮政编码和 zip 正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找最终的邮政编码和邮政编码正则表达式.我正在寻找能够覆盖世界大部分地区(希望是所有地区)的内容.

I'm looking for the ultimate postal code and zip code regex. I'm looking for something that will cover most (hopefully all) of the world.

推荐答案

没有.

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

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?

你不能.

这篇关于什么是最终的邮政编码和 zip 正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆