ZIP Code(美国邮政编码)验证 [英] ZIP Code (US Postal Code) validation

查看:29
本文介绍了ZIP Code(美国邮政编码)验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为人们会一起研究小代码项目,但我没有看到他们,所以这里是一个简单的项目:

I thought people would be working on little code projects together, but I don't see them, so here's an easy one:

验证有效美国邮政编码的代码.我知道那里有邮政编码数据库,但仍有一些用途,例如网页、快速验证以及邮政编码不断发布的事实,因此您可能需要使用弱验证.

Code that validates a valid US Zip Code. I know there are ZIP code databases out there, but there are still uses, like web pages, quick validation, and also the fact that zip codes keep getting issued, so you might want to use weak validation.

我在我的维基/博客上的一个辅助项目中写了一些关于邮政编码的内容:

I wrote a little bit about zip codes in a side project on my wiki/blog:

https://benc.fogbugz.com/default.asp?W24

还有一种新的、奇怪的邮政编码.

There is also a new, weird type of zip code.

https://benc.fogbugz.com/default.asp?W42

我可以编写 javascript 代码,但看看我们可以在这里获得多少种语言会很有趣.

I can do the javascript code, but it would be interesting to see how many languages we can get here.

推荐答案

Javascript Regex Literal:

美国邮政编码:/(^d{5}$)|(^d{5}-d{4}$)/

var isValidZip = /(^d{5}$)|(^d{5}-d{4}$)/.test("90210");

某些国家/地区使用邮政编码,这将无法使用此模式.

Some countries use Postal Codes, which would fail this pattern.

这篇关于ZIP Code(美国邮政编码)验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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