email_regex 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 +24 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +18 -0
- data/Rakefile +8 -0
- data/email_regex.gemspec +16 -0
- data/lib/email_regex.rb +50 -0
- data/test/test_email_regex.rb +53 -0
- metadata +53 -0
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
|
15
|
+
# YARD artifacts
|
16
|
+
.yardoc
|
17
|
+
_yardoc
|
18
|
+
doc/
|
19
|
+
|
20
|
+
# Ignore Emacs backups everywhere.
|
21
|
+
*~
|
22
|
+
|
23
|
+
# Ignore textmate projects
|
24
|
+
*.tmproj
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2013 Doug Wiegley
|
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.
|
21
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= email_regex
|
2
|
+
|
3
|
+
* {Homepage}[https://github.com/dougwig/email_regex.git]
|
4
|
+
* {Email}[mailto:doug at parksidesoftware.com]
|
5
|
+
|
6
|
+
== Description
|
7
|
+
|
8
|
+
Provides a valid email regex that conforms to most valid RFC edges cases (disallows backticks), and allows for a few illegal patterns that are in common use.
|
9
|
+
|
10
|
+
EmailRegex::EMAIL_ADDRESS_REGEX
|
11
|
+
|
12
|
+
== Install
|
13
|
+
|
14
|
+
$ gem install email_regex
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
See LICENSE.txt for details.
|
data/Rakefile
ADDED
data/email_regex.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'email_regex'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2013-03-11'
|
5
|
+
s.license = "MIT"
|
6
|
+
s.summary = "Validate email address regex"
|
7
|
+
s.description = "Validate email address regex"
|
8
|
+
s.authors = ["Doug Wiegley"]
|
9
|
+
s.email = 'doug@parksidesoftware.com'
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split($/)
|
12
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
13
|
+
s.require_paths = ['lib']
|
14
|
+
|
15
|
+
s.homepage = 'https://github.com/dougwig/email_regex.git'
|
16
|
+
end
|
data/lib/email_regex.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
class EmailRegex
|
2
|
+
#
|
3
|
+
# RFC822, obsolete and more lax in most cases
|
4
|
+
#
|
5
|
+
# CTL = <any ASCII control ; ( 0- 37, 0.- 31.)
|
6
|
+
# SPACE = <ASCII SP, space> ; ( 40, 32.)
|
7
|
+
# specials = "(" / ")" / "<" / ">" / "@" ; Must be in quoted-
|
8
|
+
# / "," / ";" / ":" / "\" / <"> ; string, to use
|
9
|
+
# / "." / "[" / "]" ; within a word.
|
10
|
+
# atom = 1*<any CHAR except specials, SPACE and CTLs>
|
11
|
+
#
|
12
|
+
# qtext = <any CHAR excepting <">, ; => may be folded "\" & CR, and including linear-white-space>
|
13
|
+
# quoted-pair = "\" CHAR ; may quote any char
|
14
|
+
# quoted-string = <"> *(qtext/quoted-pair) <">; Regular qtext or quoted chars.
|
15
|
+
# word = atom / quoted-string
|
16
|
+
#
|
17
|
+
# local-part = word *("." word) ; uninterpreted
|
18
|
+
#
|
19
|
+
# domain-ref = atom ; symbolic reference
|
20
|
+
# sub-domain = domain-ref / domain-literal
|
21
|
+
# domain = sub-domain *("." sub-domain)
|
22
|
+
#
|
23
|
+
# addr-spec = local-part "@" domain ; global address
|
24
|
+
#
|
25
|
+
|
26
|
+
ctl = '\x00-\x1f'
|
27
|
+
space = ' '
|
28
|
+
specials = '\(\)\<\>\@\,\;\:\\\"\.\[\]'
|
29
|
+
atom = '[^' + ctl + space + specials + ']+?'
|
30
|
+
dot_atom = atom + '(?:\.' + atom + ')*' # in common use, allowed by RFC2822
|
31
|
+
|
32
|
+
qtext = '[^\"\`]+'
|
33
|
+
quoted_pair = '\\.'
|
34
|
+
quoted_string = '\"(?:' + qtext + '|' + quoted_pair + ')+?\"'
|
35
|
+
word = '(?:' + dot_atom + '|' + quoted_string + ')'
|
36
|
+
|
37
|
+
local_part = word # ignore word[.word]
|
38
|
+
|
39
|
+
domain_ref = dot_atom
|
40
|
+
domain_literal = '\[' + atom + '(?:[\.\:]' + atom + ')*\]' # only used for IPv4/IPv6 addresses
|
41
|
+
sub_domain = '(?:' + domain_ref + '|' + domain_literal + ')'
|
42
|
+
domain = sub_domain
|
43
|
+
|
44
|
+
addr_spec = local_part + '\@' + domain
|
45
|
+
|
46
|
+
addr_ws = '\s*(' + addr_spec + ')\s*'
|
47
|
+
addr_list = '^' + addr_ws + '(?:,' + addr_ws + ')*$'
|
48
|
+
|
49
|
+
EMAIL_ADDRESS_REGEX = /#{addr_list}/
|
50
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'email_regex'
|
3
|
+
|
4
|
+
class EmailRegexTest < Test::Unit::TestCase
|
5
|
+
def test_good_addresses
|
6
|
+
good = [
|
7
|
+
'doug@example.com',
|
8
|
+
'"doug"@example.com',
|
9
|
+
'"sp sp"@example.com',
|
10
|
+
'"foo"@a,"foo"@b',
|
11
|
+
'foo@example',
|
12
|
+
'foo@[1.2.3.4]',
|
13
|
+
'ipv6@[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]',
|
14
|
+
'a@b.c,d@e.f',
|
15
|
+
'a@b.c,d@e.f,g@h.i',
|
16
|
+
' a@b.c,d@e.f,g@h.i ',
|
17
|
+
'a@b.c , d@e.f,g@h.i',
|
18
|
+
'a@b.c,d@e.f ,g@h.i',
|
19
|
+
'a@b.c,d@e.f, g@h.i',
|
20
|
+
'doug-test@a.com',
|
21
|
+
'doug_test@a.com',
|
22
|
+
'doug.test@a.com',
|
23
|
+
'doug+test@a.com',
|
24
|
+
'a@f-w.junk',
|
25
|
+
'a@f_w.junk' # this is an illegal DNS name, but in common use
|
26
|
+
]
|
27
|
+
good.each do |x|
|
28
|
+
assert x =~ EmailRegex::EMAIL_ADDRESS_REGEX
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_bad_addresses
|
33
|
+
bad = [
|
34
|
+
'doug@',
|
35
|
+
'@example.com',
|
36
|
+
'sp sp@example.com',
|
37
|
+
#'doug@[foo.com]', # not worth the complexity to check for this
|
38
|
+
#'doug@[foo]', # not worth the complexity to check for this
|
39
|
+
'doug@a,',
|
40
|
+
',doug@a',
|
41
|
+
'a @b',
|
42
|
+
'a@ b',
|
43
|
+
'""@a',
|
44
|
+
'doug',
|
45
|
+
'doug,jim',
|
46
|
+
'"hello`reboot`goodbye"@example.com'
|
47
|
+
]
|
48
|
+
bad.each do |x|
|
49
|
+
assert (not x =~ EmailRegex::EMAIL_ADDRESS_REGEX)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: email_regex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Doug Wiegley
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-11 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Validate email address regex
|
15
|
+
email: doug@parksidesoftware.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .gitignore
|
21
|
+
- LICENSE.txt
|
22
|
+
- README.rdoc
|
23
|
+
- Rakefile
|
24
|
+
- email_regex.gemspec
|
25
|
+
- lib/email_regex.rb
|
26
|
+
- test/test_email_regex.rb
|
27
|
+
homepage: https://github.com/dougwig/email_regex.git
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 1.8.17
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: Validate email address regex
|
52
|
+
test_files:
|
53
|
+
- test/test_email_regex.rb
|