zoukankan      html  css  js  c++  java
  • validates

    In addition to those validations, information is provided with each macro about its specific options.

    ValidationMacroOptions

    Validate acceptance of terms.

    validates_acceptance_of :terms
    validates :terms, acceptance: true
    :message
    :accept # Specify the accepted value. Default: 1.

    Validate associated documents when the parent is validated. This only validates documents in memory.

    validates_associated :albums
    validates :albums, associated: true
    :message

    Validate confirmation of a field, with a "_confirmation" suffix.

    validates_confirmation_of :password
    validates :password, confirmation: true
    :message

    Validate items are not in a list.

    validates_exclusion_of :employers, in: [ "SoundCloud" ]
    validates :employers, exclusion: { in: [ "SoundCloud" ] }
    :in # Required list of values.
    :message

    Validate the format of a field.

    validates_format_of :title, with: /Aw+/
    validates :title, format: { with: /Aw+/ }
    :allow_blank # Whether the field can be blank.
    :in # A list or range of values.
    :message
    :with # A regular expression to match.
    :without # A regular expression not to match.

    Validate items are included in a list.

    validates_inclusion_of :employers, in: [ "SoundCloud" ]
    validates :employers, inclusion: { in: [ "SoundCloud" ] }
    :allow_blank # Whether the field can be blank.
    :in # Required list of values.
    :message

    Validate the length of a field.

    validates_length_of :password, minimum: 8, maximum: 16
    validates :password, length: { minimum: 8, maximum: 16 }
    :allow_blank # Whether to validate blank attributes.
    :in # The range the length can fall within.
    :maximum # The maximum length of the attribute.
    :message
    :minimum # The minimum length of the attribute.
    :tokenizer # A block tokenizer.
    :too_long # Custom message if too long.
    :too_short # Custom message if too short.
    :within # Range the length can fall within.
    :wrong_length # Custom message for an incorrect length.

    Validate the numericality of a field.

    validates_numericality_of :age, even: true
    validates :age, numericality: { even: true }
    :equal_to # A value the field must be exactly.
    :even # Set that the value must be even.
    :greater_than
    :greater_than_or_equal_to
    :less_than
    :less_than_or_equal_to
    :message
    :odd # Set that the value must be odd.
    :only_integer # Set whether the value has to be an integer.

    Validate that an attribute exists. Note that if you add a presence validation to a relation, then Mongoid will enable autosave for that relation.

    validates_presence_of :name
    validates :name, presence: true
    :message

    Validate that an attribute is unique. Note that for embedded documents, this will only check that the field is unique within the context of the parent document, not the entire database.

    validates_uniqueness_of :name
    validates :name, uniqueness: true
    :message
    :case_sensitive # Whether to use case sensitive matching.
    :scope # Scope checks to the value of this field.
  • 相关阅读:
    美女程序员是如何将QQ转换成题目中那串数字的--读博文《找女神要QQ号码》
    C#微信开发-微信JS-SDK(1)之通过config接口注入权限验证配置
    AjaxUpload.3.5.js之ASP.NET 文件上传
    web开发常用的js验证,利用正则表达式验证邮箱、手机、身份证等输入
    HNU_结对项目_小初高数学学习软件_功能说明
    转载:alpha测试和beta测试的区别;黑盒测试和白盒测试的区别;
    HNU_个人项目_中小学数学卷子自动生成程序_简要分析HnuLyx代码
    文件与磁盘空间管理---外存分配方式、存储空间管理
    Java程序设计——不一样的开始 IP地址判定
    Java编程思想—八皇后问题(数组法、堆栈法)
  • 原文地址:https://www.cnblogs.com/qinyan20/p/3850872.html
Copyright © 2011-2022 走看看