LoginSignup
2
2

More than 5 years have passed since last update.

Emailを有効なメールアドレスか判断するvalidation

Posted at

モデルファイルに以下を追加

user.rb
VALID_EMAIL_FORMAT = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validate :email, format: { with:VALID_EMAIL_FORMAT }

これで
moziretsu@moziretsu.moziretsu
と言った一般的なemailのフォーマットに乗っとたメールアドレス以外無効になるようになります。

2
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
2
2