Sha256: 77ac61bd9ba7903499de9b20696f120f6d1de7991d1d49bb06628729a5365a1a

Contents?: true

Size: 490 Bytes

Versions: 2

Compression:

Stored size: 490 Bytes

Contents

class AlphaValidator < ActiveModel::EachValidator

  def validate_each(record, attribute, value)
    if options[:strict]
      format = /^[A-Za-z]+$/i # Strict: requires no spaces to be included
    elsif options[:lowercase]
      format = /^[a-z]+$/
    elsif options[:uppercase]
      format = /^[A-Z]+$/
    else
      format = /^[A-Za-z ]+$/i
    end

    unless value =~ format
      record.errors[attribute] << (options[:message] || I18n.t('errors.messages.alpha'))
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flash_validators-1.1.0 lib/flash_validators/validators/alpha_validator.rb
flash_validators-1.0.0 lib/flash_validators/validators/alpha_validator.rb