The above example performs a validation using the built-in validator “InclusionIn”. It checks the value of the field “type” in a domain list. If the value is not included in the method then the validator will fail and return false. The following built-in validators are available:

Name Explanation Example
PresenceOf Validates that a field’s value isn’t null or empty string. This validator is automatically added based on the attributes marked as not null on the mapped table Example
Email Validates that field contains a valid email format Example
ExclusionIn Validates that a value is not within a list of possible values Example
InclusionIn Validates that a value is within a list of possible values Example
Numericality Validates that a field has a numeric format Example
Regex Validates that the value of a field matches a regular expression Example
Uniqueness Validates that a field or a combination of a set of fields are not present more than once in the existing records of the related table Example
StringLength Validates the length of a string Example
Url Validates that a value has a valid URL format Example

相关文章:

  • 2021-07-19
  • 2021-06-03
  • 2021-06-19
  • 2021-05-15
  • 2021-11-17
  • 2021-06-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-25
  • 2021-08-31
  • 2022-12-23
  • 2021-08-05
  • 2022-03-06
相关资源
相似解决方案