ValidateEmail 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/ValidateEmail.gemspec +21 -0
- data/lib/ValidateEmail.rb +18 -0
- data/lib/ValidateEmail/version.rb +3 -0
- data/test/validate_email_test.rb +28 -0
- metadata +69 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ValidateEmail/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ValidateEmail"
|
7
|
+
s.version = Validateemail::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Satyaram B V"]
|
10
|
+
s.email = ["bvsatyaram@gmail.com"]
|
11
|
+
s.homepage = "http://bvsatyaram.com"
|
12
|
+
s.summary = %q{Validates email address optionally also validating the mx records}
|
13
|
+
s.description = %q{Validates email address optionally also validating the mx records}
|
14
|
+
|
15
|
+
s.rubyforge_project = "ValidateEmail"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'resolv'
|
2
|
+
|
3
|
+
module ValidateEmail
|
4
|
+
def self.validate(email, validate_mx = false)
|
5
|
+
is_valid = (email =~ /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/)
|
6
|
+
is_valid = is_valid && validate_mx_record(email) if validate_mx
|
7
|
+
|
8
|
+
return is_valid
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.validate_mx_record(email)
|
12
|
+
domain = email.match(/\@(.+)/)[1]
|
13
|
+
Resolv::DNS.open do |dns|
|
14
|
+
@mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
|
15
|
+
end
|
16
|
+
@mx.size > 0 ? true : false
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'ValidateEmail'
|
5
|
+
|
6
|
+
class ValidateEmailTest < Test::Unit::TestCase
|
7
|
+
def test_validat_email
|
8
|
+
assert !ValidateEmail.validate("bvsatyaram")
|
9
|
+
assert !ValidateEmail.validate("bvsatyaram@example")
|
10
|
+
assert !ValidateEmail.validate("bvsatyaram.com")
|
11
|
+
assert ValidateEmail.validate("bvsatyaram@example.com")
|
12
|
+
assert ValidateEmail.validate("bv_satyaram@example.com")
|
13
|
+
assert ValidateEmail.validate("bv.satyaram@example.com")
|
14
|
+
assert ValidateEmail.validate("bv-satyaram@example.com")
|
15
|
+
assert ValidateEmail.validate("bvsatyaram@example.org")
|
16
|
+
assert ValidateEmail.validate("bvsatyaram@fhgtrityhgs.com")
|
17
|
+
|
18
|
+
assert !ValidateEmail.validate("bvsatyaram", true)
|
19
|
+
assert !ValidateEmail.validate("bvsatyaram@example", true)
|
20
|
+
assert !ValidateEmail.validate("bvsatyaram.com", true)
|
21
|
+
assert ValidateEmail.validate("bvsatyaram@bvsatyaram.com", true)
|
22
|
+
assert ValidateEmail.validate("bv_satyaram@bvsatyaram.com", true)
|
23
|
+
assert ValidateEmail.validate("bv.satyaram@bvsatyaram.com", true)
|
24
|
+
assert ValidateEmail.validate("bv-satyaram@bvsatyaram.com", true)
|
25
|
+
assert ValidateEmail.validate("bvsatyaram@rubygems.org", true)
|
26
|
+
assert !ValidateEmail.validate("bvsatyaram@fhgtrityhgs.com", true)
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ValidateEmail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Satyaram B V
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-04-27 00:00:00 +05:30
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Validates email address optionally also validating the mx records
|
22
|
+
email:
|
23
|
+
- bvsatyaram@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- Gemfile
|
33
|
+
- Rakefile
|
34
|
+
- ValidateEmail.gemspec
|
35
|
+
- lib/ValidateEmail.rb
|
36
|
+
- lib/ValidateEmail/version.rb
|
37
|
+
- test/validate_email_test.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://bvsatyaram.com
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project: ValidateEmail
|
64
|
+
rubygems_version: 1.3.6
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Validates email address optionally also validating the mx records
|
68
|
+
test_files: []
|
69
|
+
|