【Node.js】PhoneやEmailのばらつきを正規化

こんにちは、フリーランスエンジニアの太田雅昭です。

正規化の必要性

例えば電話番号だと、国際的な場合以下のパターンは同じところに届きます。

+81 90 xxxx xxxx
+81 090 xxxx xxxx

メールアドレスなら以下のようなものです。Gmailは特に自由度が高いです。なお実在するアドレスを載せるわけにはいきませんのでドメインは変えていますが、以下はGmailの場合の話です。

xxx@example.com
xx.x@example.com

こうしたことから、電話番号やEmailが一意である必要がある場合、正規化が必要になります。

ライブラリ

探してみたところ、以下の二つが良さそうなので使ってみることにしました。

電話番号

GitHub – grantila/awesome-phonenumber: Google’s libphonenumber pre-compiled with the closure compiler

Google’s libphonenumber pre-compiled with the closure compiler – GitHub – grantila/awesome-phonenumber: Google’s libphonenumber pre-compiled with the closure compiler

Email

GitHub – johno/normalize-email: Normalize + and . emails — ex.ample+foobar@gmail.com => example@gmail.com

Normalize + and . emails — ex.ample+foobar@gmail.com => example@gmail.com – GitHub – johno/normalize-email: Normalize + and . emails — ex.ample+foobar@gmail.com => example@gmail.com

しばらく使ってみます。

小話

早く暖かくならないかなー。と思う今日この頃です。春が待ち遠しいです。