Class: OmgValidator::Validators::AlphaNumericDashValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- OmgValidator::Validators::AlphaNumericDashValidator
- Defined in:
- lib/omg_validator/validators/alpha_numeric_dash_validator.rb
Overview
Checks whether input only contains alpha-numeric characters and dashes.
Matches:
alpha-num21, alpha-dash, testing, hello-world2
Does not Match:
sub.domain, alpha_score
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/omg_validator/validators/alpha_numeric_dash_validator.rb', line 14 def validate_each(record, attribute, value) return nil if value.blank? reg = /^([-a-z0-9_-])+$/i unless reg.match(value) record.errors[attribute] = "must contain only alpha-numeric characters and dashes" end end |