Class: OmgValidator::Validators::AlphaNumericValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- OmgValidator::Validators::AlphaNumericValidator
- Defined in:
- lib/omg_validator/validators/alpha_numeric_validator.rb
Overview
Checks whether input only contains alpha-numberic characters
validates :title, alpha_numberic: true
Instance Method Summary (collapse)
Instance Method Details
- (Object) validate_each(record, attribute, value)
7 8 9 10 11 12 13 |
# File 'lib/omg_validator/validators/alpha_numeric_validator.rb', line 7 def validate_each(record, attribute, value) return nil if value.nil? reg = /^([a-z0-9])+$/i unless reg.match(value) record.errors[attribute] = "must contain only alpha-numeric characters" end end |