2

我想验证用户输入的邮政编码是否有效。

for example用户输入009876654且无效,则应给出错误消息。

我知道我可以使用javascript regulr expression或使用ajax-zip-code-database

但我不想要上述任何一个。我需要一些插件之类的东西,它可以向某些在线应用程序发送请求以检查它是否有效。我想要这个,因为我不想在未来有邮政编码或新邮政编码的变化 -添加代码。

PS :- 我不想使用javascript或使用ajax-zip-code-database

4

2 回答 2

1

webservicex上有一个 Web 服务,它可以为您提供来自 GET 甚至 POST 调用的 XML 结果。我从未使用过它,但它似乎是您正在寻找的东西。

不存在的邮政编码返回空数据集

wget http://www.webservicex.net/uszip.asm /GetInfoByZIP?USZip=60001

<?xml version="1.0" encoding="utf-8"?>
<NewDataSet>
  <Table>
  <CITY>Alden</CITY>
  <STATE>IL</STATE>
  <ZIP>60001</ZIP>
  <AREA_CODE>815</AREA_CODE>
  <TIME_ZONE>C</TIME_ZONE>
</Table>
</NewDataSet>
于 2010-07-26T21:35:30.520 回答
0

假设您的应用程序与其使用条款在商业上兼容,我想知道您是否可以使用 Google 的 gecoder 服务来查找邮政编码,然后检查结果以查看它是否存在。我假设如果你得到一个邮政编码和一个健全的 lat, lng 对,你可以断定邮政编码是真实的。

下面的代码(诚然使用现已弃用的 V2 API 显示了一种以美国为中心的搜索方法)。优点是最终用户和 Google 计算资源和带宽用于进行验证。

我不知道这对您的目的是否有点沉重,尽管我发现 Google 的 gecoder 速度非常快。

gecoder = new GClientGeocoder();

geocoder.getLocations(zipcode, function(response) {
    if (response && response.Status.code === 200) {
        var places = response.Placemark;
        for (var p in places) {
            if (places[p].AddressDetails.Country.CountryNameCode === 'US') {
                // lat => places[p].Point.coordinates[1],
                // lng => places[p].Point.coordinates[0],
                // zip => places[p].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber
            }
        }
    }
});
于 2010-07-13T13:32:18.577 回答