validates_as_mobile 0.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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/lib/validates_as_mobile/version.rb +3 -0
- data/lib/validates_as_mobile.rb +18 -0
- data/validates_as_mobile.gemspec +19 -0
- metadata +53 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Sergey Polischuk
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
## ValidatesAsMobile
|
2
|
+
|
3
|
+
This is simple validator for Russian mobile numbers.
|
4
|
+
Mobile numbers must match with formats:
|
5
|
+
|
6
|
+
+79000000000
|
7
|
+
+7900 000 00 00
|
8
|
+
+7900-000-00-00
|
9
|
+
+7(900)0000000
|
10
|
+
+7 (900)0000000
|
11
|
+
+7(900) 000 00 00
|
12
|
+
+7(900)000-00-00
|
13
|
+
+7(903)-000-00-00
|
14
|
+
|
15
|
+
Or:
|
16
|
+
|
17
|
+
89000000000
|
18
|
+
8900 000 00 00
|
19
|
+
8900-000-00-00
|
20
|
+
8(900)0000000
|
21
|
+
8 (900)0000000
|
22
|
+
8(900) 000 00 00
|
23
|
+
8(900)000-00-00
|
24
|
+
8(900)-000-00-00
|
25
|
+
|
26
|
+
## Install
|
27
|
+
|
28
|
+
```bash
|
29
|
+
gem install validates_as_mobile
|
30
|
+
```
|
31
|
+
|
32
|
+
## Usage example
|
33
|
+
|
34
|
+
Add parameter for phone number to your model. Then add to model this validation:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
class Person < ActiveRecord::Base
|
38
|
+
validates_as_mobile :phone_number, :message => "Your error message here", :allow_nil => false
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
Default error message is "Not Russian mobile phone format."
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'validates_as_mobile/version'
|
3
|
+
|
4
|
+
module ValidatesAsMobile
|
5
|
+
def validates_as_mobile(*args)
|
6
|
+
regexp_not_blank = /\A((8|\+7)[\s]?)\(?(9[0-3][0-9]|941|95[0-6]|958|96[0-8]|97[0-1]|98[0-5]|98[7-9]|99[2-7]|999)\)?[-.|\s ]?([0-9]{3})[-.|\s]?([0-9]{2})[-.|\s ]?([0-9]{2})\z/
|
7
|
+
regexp_with_blank = /\A(((8|\+7)[\s]?)\(?(9[0-3][0-9]|941|95[0-6]|958|96[0-8]|97[0-1]|98[0-5]|98[7-9]|99[2-7]|999)\)?[-.|\s ]?([0-9]{3})[-.|\s]?([0-9]{2})[-.|\s ]?([0-9]{2}))?\z/
|
8
|
+
|
9
|
+
configuration = { :message => 'Not Russian mobile phone format.', :with => regexp_not_blank, :allow_nil => false }
|
10
|
+
|
11
|
+
configuration.update(args.pop) if args.last.is_a?(Hash)
|
12
|
+
configuration[:with] = regexp_with_blank if configuration[:allow_nil]
|
13
|
+
|
14
|
+
validates args.first, :format => configuration
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
ActiveRecord::Base.extend ValidateAsMobile
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/validates_as_mobile/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.authors = ["Sergey Polischuk"]
|
6
|
+
s.email = ["mayorserega@gmail.com"]
|
7
|
+
s.description = %q{This is simple validator for Russian mobile numbers.}
|
8
|
+
s.summary = %q{Validator for Russian mobile numbers}
|
9
|
+
s.homepage = "https://github.com/palya/validates_as_mobile"
|
10
|
+
|
11
|
+
s.rubyforge_project = "validates_as_mobile"
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split($\)
|
14
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
|
+
s.name = "validates_as_mobile"
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.version = ValidatesAsMobile::VERSION
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: validates_as_mobile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sergey Polischuk
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-12 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: This is simple validator for Russian mobile numbers.
|
15
|
+
email:
|
16
|
+
- mayorserega@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/validates_as_mobile.rb
|
27
|
+
- lib/validates_as_mobile/version.rb
|
28
|
+
- validates_as_mobile.gemspec
|
29
|
+
homepage: https://github.com/palya/validates_as_mobile
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project: validates_as_mobile
|
49
|
+
rubygems_version: 1.8.24
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: Validator for Russian mobile numbers
|
53
|
+
test_files: []
|