presence: true
空白禁止
allow_blank: true
空の検証をスキップさせるときに使用する
:length => { :maximum => 20 }
入力長さを指定する、上記の例では20文字まで
:uniqueness => true
データの内容がユニークである事、つまりデータベースに同じ内容のデータがない事
名前やmailは重複しないようにとかに使う
:numericality => only_integer
整数のみ
:format => { :with => /regex/ }
正規表現にマッチする
:confirmation => true
パスワードなどの確認入力項目が、比較元項目と一致しているかチェックを行う
:exclusion => { :in => %w(ruby python perl ) }
指定された値が含まれないことをチェックする
:inclusion => { :in => %w(small medium large) }
指定された値が含まれることをチェックする
他の例: validates :lock, inclusion: { allow_blank: true, in: %w(0 1 2) }