Class: OmgValidator::Validators::AlphaValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/omg_validator/validators/alpha_validator.rb

Overview

Checks whether input only contains alphabetic characters

validates :name, alpha: true

matches: alpha, testing, Hello, does not match: sub.domain, alpha-dash, id=343, (232)

Instance Method Summary (collapse)

Instance Method Details

- (Object) validate_each(record, attribute, value)



10
11
12
13
14
15
16
# File 'lib/omg_validator/validators/alpha_validator.rb', line 10

def validate_each(record, attribute, value)
  return nil if value.nil?
  reg = /^([a-z])+$/i
  unless reg.match(value)
    record.errors[attribute] = "must contain only alphabetic characters"
  end
end