Swiftで郵便番号が実在するかしないか確認するバリデーション
他のAPIを使う必要がないのでやりやすいです。
//郵便番号のバリデーション
CLGeocoder().geocodeAddressString("0000000", completionHandler: {(placemarks, error) -> Void in
//存在しない郵便番号
if((error) != nil){
print("存在しない郵便番号です")
}
else{
//入力がすべて正しい
print("成功")
}
})
CLGeocoderを使ってエラーが出るか出ないかで判別。
入力する郵便番号はハイフン無しで文字列型なので注意が必要。
おすすめ情報