Phone Validation plugin

Plugin details

A plugin that would not just check the well-formedness of a phone number, but also check that the NPA/NXX combination is real.

My idea for the plugin includes the following:

1. A generator to create the db migration necessary for the new table.
2. A rake task to load in new versions of the db. (it gets updated 4 times a year)
3. A "validates_phone_authenticity_of" function added to ActiveRecord::Validations.

Bonus points would be to cache the table in memory upon application load so that you don't need to do a db hit every validation. The data is nearly static, so refreshing only on app restart is sufficient.

(I'm totally open to other ideas--let me know if you come up with anything. One idea I have, for v2, is to distinguish cell phone from normal echanges, and to send an SMS message to validate. Another obvious next step is to make it work internationally; that's where the open source community should help.)

This plugin is going to be super popular wherever phone numbers are used.

Repositoryhttp://svn.savvica.com/public/plugins/phone_validation/ Author Wesley Moxam Tags validation, phone LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://svn.savvica.com/public/plugins/phone_validation/
  def test_validation
    ["416-856-0342", "1-416-856-0342", "4168560342", "14168560342"].each do |number|
      valid_number = Person.create(:name => 'Bob', :phone_number => number)
      assert valid_number.valid?, "#{number} should be valid on create"
      assert valid_number.save, "#{number} should be valid on update"
    end

    ["647-272.1872aa1", "416-023-9237", "1", "1111111111", "416-856-03422", "2-416-856-0342"].each do |number|
      invalid_number = Person.create(:name => 'Jim', :phone_number => number)
      assert !invalid_number.valid?, "#{number} should be invalid on create"
      assert !invalid_number.save, "#{number} should be invalid on update"
    end
  end

  def test_mobile_numbers
    ["416-856-0342", "1-416-856-0342", "4168560342", "14168560342", "647-272-1872"].each do |number|
      assert PhoneValidation::NPANumber.is_mobile_number?(number), "#{number} should be listed as mobile"
    end

    ["613-338-3172", "1-613-338-3172", "6133383172", "16133383172", "", "xxxxxxxxxxxx"].each do |number|
      assert !PhoneValidation::NPANumber.is_mobile_number?(number), "#{number} should not be listed as a mobile number"
    end
  end


Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 3 months ago