Sha256: 22a7dfddcf76c42444b4f23320581b0454636e46e940fb88dbbc2e24d7468064

Contents?: true

Size: 375 Bytes

Versions: 11

Compression:

Stored size: 375 Bytes

Contents

class PhonePatternValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
		if !value.blank?
			first_normalize value
	    unless value.match(/^((\d){10})$/i)
	      record.errors[attribute] << "10 digit phone number, area-code first, no country code please."
	    end
		end
  end

private

	def first_normalize number
		number.to_phone
	end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
stripe_local-0.2.5 app/validators/phone_pattern_validator.rb
stripe_local-0.2.4 app/validators/phone_pattern_validator.rb
stripe_local-0.2.3 app/validators/phone_pattern_validator.rb
stripe_local-0.2.2 app/validators/phone_pattern_validator.rb
stripe_local-0.2.1 app/validators/phone_pattern_validator.rb
stripe_local-0.2.0 app/validators/phone_pattern_validator.rb
stripe_local-0.1.3 app/validators/phone_pattern_validator.rb
stripe_local-0.1.2 app/validators/phone_pattern_validator.rb
stripe_local-0.1.1 app/validators/phone_pattern_validator.rb
stripe_local-0.1.0 app/validators/phone_pattern_validator.rb
stripe_local-0.0.2 app/validators/phone_pattern_validator.rb