rails_email_validator 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rails_email_validator.rb +16 -13
- data/rails_email_validator.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
require 'active_model'
|
2
3
|
|
3
4
|
class EmailValidator < ActiveModel::EachValidator
|
@@ -18,22 +19,24 @@ class EmailValidator < ActiveModel::EachValidator
|
|
18
19
|
|
19
20
|
# main validator for email
|
20
21
|
def validate_each(record, attribute, value)
|
21
|
-
|
22
|
-
|
22
|
+
unless value.blank?
|
23
|
+
# split local and domain part
|
24
|
+
(local_part, domain_part) = value.split('@', 2)
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
+
# pre var
|
27
|
+
valid = true
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
# check syntax
|
30
|
+
valid = false unless local_part =~ /\A[A-Za-z0-9.!\#$%&'*+-\/=?^_`{|}~]+\Z/
|
31
|
+
valid = false unless domain_part =~ /\A((?:[-a-zA-Z0-9]+\.)+[a-zA-Z]{2,})\Z/
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
# check mx
|
34
|
+
if valid and validate_mx?
|
35
|
+
valid = false unless has_mx? domain_part
|
36
|
+
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
+
# email valid
|
39
|
+
record.errors.add(attribute, :invalid) unless valid
|
40
|
+
end
|
38
41
|
end
|
39
42
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Marco Scholl
|
@@ -140,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
140
|
requirements:
|
141
141
|
- - ">="
|
142
142
|
- !ruby/object:Gem::Version
|
143
|
-
hash:
|
143
|
+
hash: 4213132792556836098
|
144
144
|
segments:
|
145
145
|
- 0
|
146
146
|
version: "0"
|