3
2

More than 1 year has passed since last update.

【Swift】郵便番号が実在するかしないか確認するバリデーション

Last updated at Posted at 2021-10-19

Swiftで郵便番号が実在するかしないか確認するバリデーション

他のAPIを使う必要がないのでやりやすいです。

//郵便番号のバリデーション
CLGeocoder().geocodeAddressString("0000000", completionHandler: {(placemarks, error) -> Void in
    //存在しない郵便番号
    if((error) != nil){
        print("存在しない郵便番号です")
    }
    else{
        //入力がすべて正しい
        print("成功")
    }
})

CLGeocoderを使ってエラーが出るか出ないかで判別。

入力する郵便番号はハイフン無しで文字列型なので注意が必要。

おすすめ情報

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2