rails 模型驗證

validates_presence_of  :你要驗證的屬性,  :messaege => '用戶名不能爲空!'


validates_uniqueness_of :你要驗證的屬性,  :message => "國家代碼重複"


validates_length_of :你要驗證的屬性, :in => 3..15, :message => "用戶名長度須爲3到15位字母或數字"

attr_accessor :password1

attr_accessor :password1_confirmation

validates_confirmation_of :password1, :message => "確認密碼不一致!"


validates_presence_of :password, :message => "密碼不能爲空!"


validates_format_of  :你要驗證的屬性 ,
    :with => %r{.(jpg|gif|png)$}i  ,
    :message => "圖片格式必須爲 .jpg 或 .gif 或 .png 格式."


validates_numericality_of :orderby, :only_integer => true,  :message => "順序號必須是數值!"


validates_numericality_of :你要驗證的屬性,:message => "必須是數字!", :only_integer => true
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章