Sha256: b886c8fa0ae3b02654690146ef0df9c2f05cc8d2213e0aeab0fe198bec9415f8

Contents?: true

Size: 439 Bytes

Versions: 2

Compression:

Stored size: 439 Bytes

Contents

class AlphaNumericValidator < ActiveModel::EachValidator

  def validate_each(record, attribute, value)
    strict_mode = options[:strict] || false

    if strict_mode
      format = /^[A-Za-z0-9]+$/i # Strict: requires no spaces to be included
    else
      format = /^[A-Za-z0-9 ]+$/i
    end

    unless value =~ format
      record.errors[attribute] << (options[:message] || I18n.t('errors.messages.alpha_numeric'))
    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_numeric_validator.rb
flash_validators-1.0.0 lib/flash_validators/validators/alpha_numeric_validator.rb