simple_phone_validation 1.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6658d03dee1624727db25c5794028e61b05ff761d9bea76a5323b2431a037a2e
4
+ data.tar.gz: '09a28d822f45a3144b472ed5acc6b6c84e4276abdf2b6fb46bc6d0935893b181'
5
+ SHA512:
6
+ metadata.gz: '09b338178cf4b4d60ee3faaa96c4b32e7640d1c3fce92acffe9a0c8eb844cb8e8ca028e7e4765938b2056617b145f170c5ff7d965dc41037a755a98a683354b6'
7
+ data.tar.gz: 7101f2d0e055ad1598530f1c87c1d30e0cb2f2ca8d22e451754bca4c7fb3f0875310f896159f7345948f86c425f9b4b3aeb10ff3a4e951f00f5226f538bf6ac0
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Fabien Karquel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ # SimplePhoneValidation
2
+ Simple custom validator for phone numbers using a reg exp.
3
+
4
+ The reg exp used is:
5
+ ```
6
+ /((?:\+|00)[17](?: |\-)?|(?:\+|00)[1-9]\d{0,2}(?: |\-)?|(?:\+|00)1\-\d{3}(?: |\-)?)?(0\d|\([0-9]{3}\)|[1-9]{0,3})(?:((?: |\-)[0-9]{2}){4}|((?:[0-9]{2}){4})|((?: |\-)[0-9]{3}(?: |\-)[0-9]{4})|([0-9]{7}))/
7
+ ```
8
+
9
+ It covers:
10
+ - as valid numbers
11
+ ```
12
+ 0123456789
13
+ +33698912549
14
+ +33 6 79 91 25 49
15
+ +33-6-79-91-25-49
16
+ (555)-555-5555
17
+ 18005551234
18
+ 1 800 555 1234
19
+ +1 800 555-1234
20
+ +86 800 555 1234
21
+ 1-800-555-1234
22
+ 1 (800) 555-1234
23
+ (800) 555-1234
24
+ (800)5551234
25
+ 800-555-1234
26
+ ```
27
+ - as invalid numbers
28
+ ```
29
+ abcdefghij
30
+ 935 263223 64 949
31
+ 067 9 91 254 9
32
+ ```
33
+
34
+
35
+ ## Usage
36
+ ```
37
+ validates :my_phone_attribute, phone: true
38
+ validates :my_other_phone, phone: true, allow_blank: true
39
+ ```
40
+
41
+ ## Installation
42
+ Add this line to your application's Gemfile:
43
+
44
+ ```ruby
45
+ gem 'simple_phone_validation'
46
+ ```
47
+
48
+ And then execute:
49
+ ```bash
50
+ $ bundle
51
+ ```
52
+
53
+ Or install it yourself as:
54
+ ```bash
55
+ $ gem install simple_phone_validation
56
+ ```
57
+
58
+ ## License
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'SimplePhoneValidation'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,4 @@
1
+ en:
2
+ global:
3
+ errors:
4
+ phone_format: Invalid phone number
@@ -0,0 +1,8 @@
1
+ require 'simple_phone_validation/railtie'
2
+ require 'simple_phone_validation/phone_validator'
3
+
4
+ module SimplePhoneValidation
5
+ class Engine < Rails::Engine
6
+ end
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,12 @@
1
+ class PhoneValidator < ActiveModel::EachValidator
2
+
3
+ PHONE_REG_EXP = /((?:\+|00)[17](?: |\-)?|(?:\+|00)[1-9]\d{0,2}(?: |\-)?|(?:\+|00)1\-\d{3}(?: |\-)?)?(0\d|\([0-9]{3}\)|[1-9]{0,3})(?:((?: |\-)[0-9]{2}){4}|((?:[0-9]{2}){4})|((?: |\-)[0-9]{3}(?: |\-)[0-9]{4})|([0-9]{7}))/
4
+
5
+ def validate_each(record, attribute, value)
6
+ return if options[:allow_blank] && value.blank?
7
+
8
+ unless value =~ PHONE_REG_EXP
9
+ record.errors[attribute] << (options[:message] || I18n.t('global.errors.phone_format'))
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module SimplePhoneValidation
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module SimplePhoneValidation
2
+ VERSION = '1.0.1'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :simple_phone_validation do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_phone_validation
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Fabien Karquel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Description of SimplePhoneValidation.
42
+ email:
43
+ - fabien.karquel@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - config/locales/en.yml
52
+ - lib/simple_phone_validation.rb
53
+ - lib/simple_phone_validation/phone_validator.rb
54
+ - lib/simple_phone_validation/railtie.rb
55
+ - lib/simple_phone_validation/version.rb
56
+ - lib/tasks/simple_phone_validation_tasks.rake
57
+ homepage: https://github.com/karquelf/simple_phone_validation
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.7.6
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Summary of SimplePhoneValidation.
81
+ test_files: []