Class: Simple::Validators::UsernameValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Simple::Validators::UsernameValidator
- Defined in:
- lib/simple/validators/username_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/simple/validators/username_validator.rb', line 4 def validate_each(record, attribute, value) return if value.blank? unless value =~ /^[a-z0-9\-_]+$/ = [:message] || 'is not valid - only letters, numbers, hyphens and underscores are allowed' record.errors[attribute] << end end |