Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Phone validator for Rails / ActiveModel 3+
Ruby
branch: master

This branch is 6 commits ahead of chap:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.document
.gitignore
.rvmrc
Gemfile
Gemfile.lock
LICENSE.txt
README.rdoc
Rakefile
VERSION
phone-validator.gemspec

README.rdoc

Phone Validator validates 10 digit numbers that are optionally separated by dashes.

valid:

123-456-7890
1234567890
919.068.7321 x81605
(919)068-7321 x81605
(919) 068-7321 x81605
1-(919) 068-7321
827-057-1719 x1960
(656)264-6225
1-128-136-1042 x981

invalid:

blank
nil
123
123--123
123x1

Installation

Include the gem in your Gemfile:

gem 'phone-validator'

Example Usage

class User < ActiveRecord::Base
  validates :phone, :phone => true
end

or

class User < ActiveRecord::Base
  validates :phone, :phone => { :message => "my custom error message."}
end

or

class user < ActiveRecord::Base
  # To allow blank phone numbers or valid phone numbers use this
  validates :phone, :phone => {:allow_empty => true}
end
Something went wrong with that request. Please try again.