Sha256: 9c029d5c6df4217be43c95d75bf5cc7d1d44a97af4df01d926a110f923910537

Contents?: true

Size: 341 Bytes

Versions: 3

Compression:

Stored size: 341 Bytes

Contents

class PhoneNumberFormatValidator < ActiveModel::EachValidator
  def validate_each(object, attribute, value)
    unless value =~ /\A(1( |-)?)?(\(?[0-9]{3}\)?|[0-9]{3})( |-)?([0-9]{3}( |-)?[0-9]{4}|[a-zA-Z0-9]{7})\z/
      object.errors[attribute] << (options[:message] || "enter a valid 10-digit number (e.g. 587-555-5555)")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ama_validators-0.0.3 lib/ama_validators/phone_number_format_validator.rb
ama_validators-0.0.2 lib/ama_validators/phone_number_format_validator.rb
ama_validators-0.0.1 lib/ama_validators/phone_number_format_validator.rb