LoginSignup
10
11

More than 5 years have passed since last update.

validates_email_format_of を使った email バリデーション

Posted at

Eメールアドレスのバリデーションは多くのgemがあると思いますが今回は

validates_email_format_of

を使った方法で試しました.

RFC 2822 と RFC 3696 に準拠したバリデーションをしているようです.

インストール

Gemfile に下記を追加します.

gem 'validates_email_format_of'

インストールします

$ bundle install

使ってみる

こんな感じでバリデーションを設定します.

class Hoge < ActiveRecord::Base
 validates :email, :email_format => {:message => 'エラ〜メッセージ〜'}
end

簡単ですね!!

10
11
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
10
11