class PhoneValidator

Validator class for phone validations

Examples

Validates that attribute is a valid phone number. If empty value passed for attribute it fails.

class Phone < ActiveRecord::Base
  attr_accessible :number
  validates :number, phone: true
end

Validates that attribute is a possible phone number. If empty value passed for attribute it fails.

class Phone < ActiveRecord::Base
  attr_accessible :number
  validates :number, phone: { possible: true }
end

Validates that attribute is a valid phone number. Empty value is allowed to be passed.

class Phone < ActiveRecord::Base
  attr_accessible :number
  validates :number, phone: { allow_blank: true }
end

Validates that attribute is a valid phone number of specified type(s). It is also possible to check that attribute is a possible number of specified type(s). Symbol or array accepted.

class Phone < ActiveRecord::Base
  attr_accessible :number, :mobile
  validates :number, phone: { types: [:mobile, :fixed], allow_blank: true }
  validates :mobile, phone: { possible: true, types: :mobile  }
end

validates that phone is valid and it is from specified country or countries

class Phone < ActiveRecord::Base
  attr_accessible :number
  validates :number, phone: { countries: [:us, :ca] }
end

Validates that attribute does not include an extension. The default setting is to allow extensions

class Phone < ActiveRecord::Base
  attr_accessible :number
  validates :number, phone: { extensions: false }
end