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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章