Class: OmgValidator::Validators::AlphaDashValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- OmgValidator::Validators::AlphaDashValidator
- Defined in:
- lib/omg_validator/validators/alpha_dash_validator.rb
Overview
Checks whether input only contains alpha characters and dashes.
Matches:
hello, hello-world
Does not Match:
hello world!, hello_world
Instance Method Summary (collapse)
Instance Method Details
- (Object) validate_each(record, attribute, value)
14 15 16 17 18 19 20 |
# File 'lib/omg_validator/validators/alpha_dash_validator.rb', line 14 def validate_each(record, attribute, value) return nil if value.blank? reg = /^([-a-z_-])+$/i unless reg.match(value) record.errors[attribute] = "must contain only alpha characters and dashes" end end |