为应用程序设计地址验证
我计划为在我的应用程序中注册的用户设计地址验证。 可能通过邮政编码和州进行验证。
知道如何处理来自全球各地的地址吗?
我是否需要在数据库中插入所有邮政编码,然后验证地址。 对于实施有什么可能的建议吗?
谢谢并欢迎:) 克里斯普
I am planning to design an address validation for users registering in my app. Possibly validating by zipcode and state.
Any idea how to handle addresses from around the globe?
Do i need to insert all the zipcodes in the database and then validate the address. Any possible suggestion for the implementation?
Thanks and Welcome :)
Krisp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
由于邮政编码没有国际标准,并且在您完成整理之前,世界上所有邮政编码的列表都将过时,因此我建议采用较小的方法:
确定您将需要处理最多和开发的国家/地区每个人都有单独的验证规则。 确保您可以处理绝大多数用户(例如 95% 或 98%)。 对于所有其他国家/地区,只需接受他们输入的内容,无需进一步验证。
世界上有如此多不同的地址格式,因此不值得花费精力(如果可能的话)来处理所有这些格式。
Since there is no international standard for zip codes and a list of all zip codes in the world would be out of date before you were finished putting it together, I suggest a smaller approach:
Identify the countries that you will have to handle most and develop seperate validation rules for each of them. Make certain that with this you handle a vast majority of your users (e.g. 95%, or98%). For all the other countries, just accept what they enter vithout further validation.
There are so many different address formats in the world that it is just not worth the effort (if at all possible) to handle them all.
地址和邮政编码格式之间存在巨大差异,因此没有任何“标准”方法可以做到这一点。 请参阅“弗兰克的邮政地址强制指南”...
多少/什么样的你真的需要验证吗? 例如,如果用户输入他们的送货地址,他们比您更有可能知道他们当地的邮政/运输提供商需要什么特定格式。 只需给他们一个多行文本区域即可输入。 如果您需要部分信息来计算运费,请仅请求您需要的信息(例如城市/国家)
There is MASSIVE variance among address and postal code formats, such that there is not any "standard" way of doing this. See "Frank's Compulsive Guide to Postal Addresses"...
How much/what kind of validation do you really need? If the user is entering their shipping address, for example, they're more likely than you to know what particular format their local postal/shipping provider needs. Just give them a multiline textarea to enter it. If you need parts of it to calculate shipping costs, request just the information you need (City/Country, for example)
邮政编码实际上可能是一个令人头痛的问题,因为在某些地方它们可以代表非常小的区域,而在美国,它们通常代表相对较大的区域(除了在大城市,它们可能代表几个街区)。
看看加拿大,他们的邮政编码实际上可以代表非常非常小的区域。 街道两侧的两家商店通常有不同的加拿大邮政编码。 同样,在加拿大企业列表中,合并列表时,经常会看到相同地址但邮政编码略有不同。 这只是表明很多人都误解了。 就客户而言,我不知道他们真正获得正确的邮政编码有多现实。
http://www.columbia.edu/kermit/postal-ca.html
基本上,似乎每个公寓或商业住宅都有自己的邮政编码,根据我在加拿大商业地址中看到的情况,这是有意义的。
另一点是,这只是加拿大。 每个欧洲国家都会有自己的地址/邮政编码,澳大利亚、俄罗斯等也会有......如果你真的想做地址验证,这是一个重大项目。
要实际验证地址,您需要验证邮政编码、城市和街道。 在美国,人口普查会发布 TIGER 数据库文件,其中通常包含街道列表。 但对于其他国家,我不知道如何获得街道列表。 最好研究一下商业软件包(也许是 GIS 软件包之一,尽管其中很多只提供美国/加拿大的详细地址,有时还提供一些欧洲国家的详细地址)。
Postal Codes can actually be a headache because in some places they can represent very tiny areas as opposed to the US where they often represent relatively large areas (except in a big city where they may represent a few blocks).
Look at Canada, their postal codes can actually represent very very tiny areas. Two stores on opposite sides of the street often have different Canadian postal codes. Also in a list of Canadian businesses, when merging the list it is not uncommon to see the same address with a slightly different postal code. This just indicates that a lot of people get it wrong. On a customer basis I don't know how realistic it is that they actually get their exact zip code right.
http://www.columbia.edu/kermit/postal-ca.html
Basically it seems that each apartment or business dwelling may get their own zip code, which would make sense based upon what I have seen with Canadian business addresses.
The other point is that this is just Canada. Each European country will have its own address/postal code, so will Australia, Russia, etc... If you really want to do address verification, this is a major project.
To actually verify the address you need to to verify the postal code, city, and street. In the US the census releases the TIGER database files which often have a list of streets. But for other countries I don't know how you can get a list of streets. It may be best to look into a commercial package (maybe one of the GIS packages, although a lot of them only offer detailed addresses for the US/Canada and sometimes a few European countries).
完美的地址验证不能准确地放置在已开发的应用程序中,但邮政编码/邮政编码的验证可以根据国家/地区名称进行。
请检查 ' 中的正则表达式SupplementalData.xml' 来自源 xml 文件源。
通过解析 xml,您可以找到运行时传递的国家/地区代码对应的邮政编码正则表达式,您可以在其中检查它是否与国家/地区匹配。
A perfect Address validation can't be exactly placed in the already developed application, the validation of zip-code / postal code can be done as per the name of country though.
Please check the regex from the 'supplementalData.xml' xml file from the source xml-files source.
By parsing the xml you can find the corresponding postal-code regular expression for the country-code passed at the run-time, where you can check whether it's matching with country.
对此找到了另一个答案:
请参考 wiki 的链接:http://en.wikipedia.org/维基/邮政编码列表。
在这里您可以找到大多数国家的大多数邮政编码模式,您可以编写正则表达式并将其维护到数据库中,这将帮助您轻松验证邮政编码,也是一种优化的方法!
Have found another answer on this :
please refer the wiki's link : http://en.wikipedia.org/wiki/List_of_postal_codes.
Here you can find most of the zip-code patterns of most of the countries, of which you may write regex and maintain into database, which would help you to validate zip-code easily and also an optimized approach !
正如许多用户之前提到的,验证国际地址基本上是不可能的,因为各国之间没有标准,而且许多国家没有邮政系统的资源。 从技术上讲,即使在美国,美国邮政局也在苦苦挣扎。
您至少可以按国家/地区提供地址验证。 美国是最容易获得大量保险的国家之一。 为此,您需要连接到某种地址验证网络服务。 有几家公司为此提供网络服务。 需要注意的一件事是确保每个提供商都对其 API 进行地理分布,以确保他们的任何中断不会流回给您并终止您的应用程序。 除此之外,只需确保结果经过 CASS 认证即可。
为了充分披露,我是 SmartyStreets 的创始人。 我们有一个名为 LiveAddress 的地址验证 Web 服务 API。 如果您有任何疑问,非常欢迎您亲自与我联系。
As many users have mentioned previously, verifying international addresses is basically impossible because there are no standards across countries and many countries don't have the resources for their postal system. Technically speaking, even in the United States, the USPS is struggling.
On a minimum you can offer address verification on a per-country basis. One of the easiest countries where you get a lot of coverage is in the USA. To do this you need to connect to some kind of address verification web service. There are several companies which have web services for this. One thing to be careful of is ensuring that each provider has geo-distribution of their API to ensure that any outages on their part don't flow back to you and kill your application. Beyond that, just make sure the results are CASS certified.
In the interest of full disclosure, I'm the founder of SmartyStreets. We have an address verification web service API called LiveAddress. You're more than welcome to contact me personally if you have any questions.