gbdev-validates_as_phone_number 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +10 -4
- data/lib/validates_as_phone_number.rb +1 -1
- data/test/validates_as_phone_number_test.rb +6 -6
- metadata +7 -3
data/README
CHANGED
@@ -2,7 +2,7 @@ ValidatesAsPhoneNumber
|
|
2
2
|
======================
|
3
3
|
|
4
4
|
This Ruby on Rails plugin/gem implements an ActiveRecord validation helper called
|
5
|
-
validates_as_phone_number which validates
|
5
|
+
validates_as_phone_number which validates U.S. phone numbers. The helper acts as
|
6
6
|
if validates_format_of was used with a regular expression that defines:
|
7
7
|
|
8
8
|
(000) 000 0000
|
@@ -17,6 +17,13 @@ if validates_format_of was used with a regular expression that defines:
|
|
17
17
|
|
18
18
|
Installation:
|
19
19
|
=============
|
20
|
+
gem sources -a http://gems.github.com
|
21
|
+
|
22
|
+
Install the gem(s):
|
23
|
+
sudo gem install gbdev-validates_as_phone_number
|
24
|
+
|
25
|
+
Add to environment.rb initializer block:
|
26
|
+
config.gem 'gbdev-validates_as_phone_number', :version => '>=0.7.5', :lib => 'validates_as_phone_number', :source => 'http://gems.github.com'
|
20
27
|
|
21
28
|
|
22
29
|
Usage:
|
@@ -24,8 +31,7 @@ Usage:
|
|
24
31
|
In your model file do something like:
|
25
32
|
|
26
33
|
class MyClass < ActiveRecord::Base
|
27
|
-
|
28
|
-
validates_as_phone_number :work_number
|
34
|
+
validates_as_phone_number :work_phone, :message => 'Invalid work phone number format', :allow_nil => true
|
29
35
|
end
|
30
36
|
|
31
37
|
Tests:
|
@@ -34,4 +40,4 @@ Some tests have been added.
|
|
34
40
|
|
35
41
|
License:
|
36
42
|
========
|
37
|
-
See the LICENSE file
|
43
|
+
See the LICENSE file.
|
@@ -16,7 +16,7 @@ module ActiveRecord
|
|
16
16
|
module Validations
|
17
17
|
module ClassMethods
|
18
18
|
def validates_as_phone_number(*attr_names)
|
19
|
-
regExpStr = '(([0-9]{3})|((\()([0-9]{3})(\))))?([\s\.-])?([0-9]{3})([\s\.-])?([0-9]{4})([\s\.-])?([x][0-9]{1,7})?'
|
19
|
+
regExpStr = '(([0-9]{3})|((\()([0-9]{3})(\))))?([\s\.-])?([0-9]{3})([\s\.-])?([0-9]{4})([\s\.-])?([x] ?[0-9]{1,7})?'
|
20
20
|
configuration = {
|
21
21
|
:message => 'is an invalid phone number',
|
22
22
|
:with => /^#{regExpStr}$/,
|
@@ -33,11 +33,11 @@ class ValidatesAsPhoneNumberTest < Test::Unit::TestCase
|
|
33
33
|
'800-321-9876',
|
34
34
|
'321-9876x12345',
|
35
35
|
'800-321-9876x1',
|
36
|
-
'800-321-
|
37
|
-
'800-321-
|
36
|
+
'800-321-9876x 1',
|
37
|
+
'800-321-9876x1234567',
|
38
38
|
'800-321-9876 x1',
|
39
|
-
'800-321-9876
|
40
|
-
'800-321-9876
|
39
|
+
'800-321-9876 x 1',
|
40
|
+
'800-321-9876 x1234567',
|
41
41
|
'(800)-321-9876',
|
42
42
|
'(800) 321-9876'
|
43
43
|
]
|
@@ -56,8 +56,8 @@ class ValidatesAsPhoneNumberTest < Test::Unit::TestCase
|
|
56
56
|
'800-321-9876 x',
|
57
57
|
'800-321-9876 xa',
|
58
58
|
'800a321-9876',
|
59
|
-
'800-321-9876x12345678',
|
60
|
-
'800-321-9876 x12345678'
|
59
|
+
'800-321-9876x12345678',
|
60
|
+
'800-321-9876 x12345678'
|
61
61
|
]
|
62
62
|
phone_numbers.each do |number|
|
63
63
|
assert !TestRecord.new(:phone_number => number).valid?, "#{number} should be invalid."
|
metadata
CHANGED
@@ -1,21 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gbdev-validates_as_phone_number
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wes Hays
|
8
8
|
- John Dell
|
9
|
+
- Josh Susser
|
10
|
+
- Brandon Keene
|
9
11
|
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
12
14
|
|
13
|
-
date:
|
15
|
+
date: 2009-01-27 00:00:00 -08:00
|
14
16
|
default_executable:
|
15
17
|
dependencies: []
|
16
18
|
|
17
19
|
description: Rails gem that implements an ActiveRecord validation helper called validates_as_phone_number which validates U.S. phone numbers
|
18
|
-
email:
|
20
|
+
email:
|
21
|
+
- gems@gbdev.com
|
22
|
+
- opensource@pivotallabs.com
|
19
23
|
executables: []
|
20
24
|
|
21
25
|
extensions: []
|