Sha256: 4194636126240acf9fe6b3fc8e804a0914c5aaa4900c089464c8412db848ef42

Contents?: true

Size: 394 Bytes

Versions: 45

Compression:

Stored size: 394 Bytes

Contents

# An ActiveRecord validator for any phone field that you would use with effective_tel
#
# validates :phone, effective_tel: true

class EffectiveTelValidator < ActiveModel::EachValidator
  PATTERN = /\A\(\d{3}\) \d{3}-\d{4}( x\d+)?\Z/

  def validate_each(record, attribute, value)
    if value.present?
      record.errors.add(attribute, 'is invalid') unless PATTERN =~ value
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
effective_form_inputs-1.5.0 lib/validators/effective_tel_validator.rb
effective_form_inputs-1.4.1 lib/validators/effective_tel_validator.rb
effective_form_inputs-1.4.0 lib/validators/effective_tel_validator.rb
effective_form_inputs-1.3.0 app/validators/effective_tel_validator.rb
effective_form_inputs-1.2.9 app/validators/effective_tel_validator.rb
effective_form_inputs-1.2.8 app/validators/effective_tel_validator.rb
effective_form_inputs-1.2.7 app/validators/effective_tel_validator.rb
effective_form_inputs-1.2.6 app/validators/effective_tel_validator.rb
effective_form_inputs-1.2.5 app/validators/effective_tel_validator.rb
effective_form_inputs-1.2.4 app/validators/effective_tel_validator.rb
effective_form_inputs-1.2.3 app/validators/effective_tel_validator.rb
effective_form_inputs-1.2.2 app/validators/effective_tel_validator.rb
effective_form_inputs-1.2.1 app/validators/effective_tel_validator.rb
effective_form_inputs-1.2.0 app/validators/effective_tel_validator.rb
effective_form_inputs-1.1.15 app/validators/effective_tel_validator.rb
effective_form_inputs-1.1.14 app/validators/effective_tel_validator.rb
effective_form_inputs-1.1.13 app/validators/effective_tel_validator.rb
effective_form_inputs-1.1.12 app/validators/effective_tel_validator.rb
effective_form_inputs-1.1.11 app/validators/effective_tel_validator.rb
effective_form_inputs-1.1.10 app/validators/effective_tel_validator.rb