sixarm_ruby_email_address_validation 1.2.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -0,0 +1,147 @@
1
+ # SixArm.com » Ruby » <br> Email address validation using RFC 822 pattern matching
2
+
3
+ * Docs: <http://sixarm.com/sixarm_ruby_email_address_validation/doc>
4
+ * Repo: <http://github.com/sixarm/sixarm_ruby_email_address_validation>
5
+ * Email: Joel Parker Henderson, <joel@sixarm.com>
6
+
7
+
8
+ ## Introduction
9
+
10
+ Email address regular expression to validate an email address using RFC 822.
11
+
12
+ This is a gem wrapper around http://tfletcher.com/lib/rfc822.rb
13
+
14
+ For docs go to <http://sixarm.com/sixarm_ruby_email_address_validation/doc>
15
+
16
+ Want to help? We're happy to get pull requests.
17
+
18
+
19
+ ## Quickstart
20
+
21
+ Install:
22
+
23
+ gem install sixarm_ruby_email_address_validation
24
+
25
+ Bundler:
26
+
27
+ gem "sixarm_ruby_email_address_validation", "=1.3.0"
28
+
29
+ Require:
30
+
31
+ require "sixarm_ruby_email_address_validation"
32
+
33
+
34
+ ## High Security (Optional)
35
+
36
+ To enable high security for all our gems:
37
+
38
+ wget http://sixarm.com/sixarm.pem
39
+ gem cert --add sixarm.pem
40
+ gem sources --add http://sixarm.com
41
+
42
+ To install with high security:
43
+
44
+ gem install sixarm_ruby_email_address_validation --test --trust-policy HighSecurity
45
+
46
+
47
+ ## Example
48
+
49
+ if EmailAddressValidation::Pattern=~"foo@bar.com"
50
+ puts "present"
51
+ else
52
+ puts "absent"
53
+ end
54
+ => "found"
55
+
56
+
57
+ ## Pattern Match
58
+
59
+ To find an email address in a string, do the pattern match
60
+ then use the result, which is the match's string position:
61
+
62
+ Example of match position:
63
+
64
+ match_position = EmailAddressValidation::Pattern=~'foo@bar.com'
65
+ => 0
66
+
67
+ match_position = EmailAddressValidation::Pattern=~'... foo@bar.com ...'
68
+ => 4
69
+
70
+ match_position = EmailAddressValidation::Pattern=~'... hello world ...'
71
+ => nil
72
+
73
+
74
+ ## Pattern Match Exact
75
+
76
+ To do a pattern match to the entire string, use the EmailAddressValidation::PatternExact.
77
+
78
+ The entire string must be one email address.
79
+
80
+ Example of pattern match:
81
+
82
+ if EmailAddressValidation::PatternExact=~'foo@bar.com'
83
+ puts "present"
84
+ else
85
+ puts "absent"
86
+ end
87
+ => found
88
+
89
+ if EmailAddressValidation::PatternExact=~'... foo@bar.com ...'
90
+ puts "present"
91
+ else
92
+ puts "absent"
93
+ end
94
+ => absent
95
+
96
+ This pattern is especialy useful to validate an email address.
97
+
98
+ Example to validate an email address:
99
+
100
+ def valid?(email_address)
101
+ EmailAddressValidation::PatternExact=~email_address ? true : false
102
+ end
103
+
104
+
105
+ ## Rails Validation
106
+
107
+ To add email address validation to a typical Ruby On Rails model:
108
+
109
+ class User
110
+ include EmailAddressValidation
111
+ validates :email_address, :format => { :with => EmailAddressValidation::PatternExact }
112
+ end
113
+
114
+
115
+ ## Changes
116
+
117
+ * 2012-03-17 2.0.0 Upgrade for Ruby 1.9.3, minitest/spec, improved docs, new API.
118
+ * 2011-04-24 1.2.2 Upgrade for Ruby 1.9.2 and Rails 3.0.6
119
+
120
+
121
+ ## License
122
+
123
+ You may choose any of these open source licenses:
124
+
125
+ * Apache License
126
+ * BSD License
127
+ * CreativeCommons License, Non-commercial Share Alike
128
+ * GNU General Public License Version 2 (GPL 2)
129
+ * GNU Lesser General Public License (LGPL)
130
+ * MIT License
131
+ * Perl Artistic License
132
+ * Ruby License
133
+
134
+ The software is provided "as is", without warranty of any kind,
135
+ express or implied, including but not limited to the warranties of
136
+ merchantability, fitness for a particular purpose and noninfringement.
137
+
138
+ In no event shall the authors or copyright holders be liable for any
139
+ claim, damages or other liability, whether in an action of contract,
140
+ tort or otherwise, arising from, out of or in connection with the
141
+ software or the use or other dealings in the software.
142
+
143
+ This license is for the included software that is created by SixArm;
144
+ some of the included software may have its own licenses, copyrights,
145
+ authors, etc. and these do take precedence over the SixArm license.
146
+
147
+ Copyright (c) 2005-2013 Joel Parker Henderson
@@ -1,24 +1,24 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin rdoc
3
- Please see README.rdoc
3
+ Please see README
4
4
  =end
5
5
 
6
6
 
7
- module EmailAddressValidation
7
+ class EmailAddressValidation
8
8
 
9
- EMAIL_ADDRESS_QTEXT = Regexp.new '[^\\x0d\\x22\\x5c\\x80-\\xff]', nil, 'n'
10
- EMAIL_ADDRESS_DTEXT = Regexp.new '[^\\x0d\\x5b-\\x5d\\x80-\\xff]', nil, 'n'
11
- EMAIL_ADDRESS_ATOM = Regexp.new '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+', nil, 'n'
12
- EMAIL_ADDRESS_QUOTED_PAIR = Regexp.new '\\x5c[\\x00-\\x7f]', nil, 'n'
13
- EMAIL_ADDRESS_DOMAIN_LITERAL = Regexp.new "\\x5b(?:#{EMAIL_ADDRESS_DTEXT}|#{EMAIL_ADDRESS_QUOTED_PAIR})*\\x5d", nil, 'n'
14
- EMAIL_ADDRESS_QUOTED_STRING = Regexp.new "\\x22(?:#{EMAIL_ADDRESS_QTEXT}|#{EMAIL_ADDRESS_QUOTED_PAIR})*\\x22", nil, 'n'
15
- EMAIL_ADDRESS_DOMAIN_REF = EMAIL_ADDRESS_ATOM
16
- EMAIL_ADDRESS_SUB_DOMAIN = "(?:#{EMAIL_ADDRESS_DOMAIN_REF}|#{EMAIL_ADDRESS_DOMAIN_LITERAL})"
17
- EMAIL_ADDRESS_WORD = "(?:#{EMAIL_ADDRESS_ATOM}|#{EMAIL_ADDRESS_QUOTED_STRING})"
18
- EMAIL_ADDRESS_DOMAIN = "#{EMAIL_ADDRESS_SUB_DOMAIN}(?:\\x2e#{EMAIL_ADDRESS_SUB_DOMAIN})*"
19
- EMAIL_ADDRESS_LOCAL_PART = "#{EMAIL_ADDRESS_WORD}(?:\\x2e#{EMAIL_ADDRESS_WORD})*"
20
- EMAIL_ADDRESS_SPEC = "#{EMAIL_ADDRESS_LOCAL_PART}\\x40#{EMAIL_ADDRESS_DOMAIN}"
21
- EMAIL_ADDRESS_INNER_PATTERN = Regexp.new "#{EMAIL_ADDRESS_SPEC}", nil, 'n'
22
- EMAIL_ADDRESS_EXACT_PATTERN = Regexp.new "\\A#{EMAIL_ADDRESS_SPEC}\\z", nil, 'n'
9
+ QuotedText = Regexp.new '[^\\x0d\\x22\\x5c\\x80-\\xff]', nil, 'n'
10
+ DomainText = Regexp.new '[^\\x0d\\x5b-\\x5d\\x80-\\xff]', nil, 'n'
11
+ Atom = Regexp.new '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+', nil, 'n'
12
+ QuotedPair = Regexp.new '\\x5c[\\x00-\\x7f]', nil, 'n'
13
+ DomainLiteral = Regexp.new "\\x5b(?:#{QuotedText}|#{QuotedPair})*\\x5d", nil, 'n'
14
+ QuotedString = Regexp.new "\\x22(?:#{QuotedText}|#{QuotedPair})*\\x22", nil, 'n'
15
+ DomainRef = Atom
16
+ SubDomain = "(?:#{DomainRef}|#{DomainLiteral})"
17
+ Word = "(?:#{Atom}|#{QuotedString})"
18
+ Domain = "#{SubDomain}(?:\\x2e#{SubDomain})*"
19
+ LocalPart = "#{Word}(?:\\x2e#{Word})*"
20
+ Spec = "#{LocalPart}\\x40#{Domain}"
21
+ Pattern = Regexp.new "#{Spec}", nil, 'n'
22
+ PatternExact = Regexp.new "\\A#{Spec}\\z", nil, 'n'
23
23
 
24
24
  end
@@ -1,40 +1,62 @@
1
1
  # -*- coding: utf-8 -*-
2
- require 'test/unit'
3
- require 'sixarm_ruby_email_address_validation'
2
+ require 'minitest/autorun'
4
3
  require 'simplecov'
5
4
  SimpleCov.start
5
+ require 'sixarm_ruby_email_address_validation'
6
+
7
+ describe EmailAddressValidation do
8
+
9
+ describe "pattern" do
10
+
11
+ describe "with typical" do
12
+
13
+ it "success" do
14
+ (EmailAddressValidation::Pattern=~'foo@bar.com').must_equal 0
15
+ end
16
+
17
+ it "failure" do
18
+ (EmailAddressValidation::Pattern=~'foo').must_equal nil
19
+ end
20
+
21
+ describe "with chaff" do
22
+
23
+ it "success" do
24
+ (EmailAddressValidation::Pattern=~'... foo@bar.com ...').must_equal 4
25
+ end
26
+
27
+ it "failure" do
28
+ (EmailAddressValidation::Pattern=~'... foo ...').must_equal nil
29
+ end
30
+
31
+ end
32
+
33
+ end
6
34
 
7
- class Testing < Test::Unit::TestCase
35
+ end
8
36
 
9
- include EmailAddressValidation
37
+ describe "pattern exact" do
10
38
 
11
- def test_inner_pattern_success
12
- assert_equal(0,EMAIL_ADDRESS_INNER_PATTERN=~'foo@bar.com')
13
- end
39
+ describe "with typical" do
14
40
 
15
- def test_inner_pattern_failure
16
- assert_equal(nil,EMAIL_ADDRESS_INNER_PATTERN=~'foo')
17
- end
41
+ it "success" do
42
+ (EmailAddressValidation::PatternExact=~'foo@bar.com').must_equal 0
43
+ end
18
44
 
19
- def test_inner_pattern_chaff_success
20
- assert_equal(4,EMAIL_ADDRESS_INNER_PATTERN=~'... foo@bar.com ...')
21
- end
45
+ end
22
46
 
23
- def test_inner_pattern_chaff_failure
24
- assert_equal(nil,EMAIL_ADDRESS_INNER_PATTERN=~'... foo ...')
25
- end
47
+ describe "with chaff" do
26
48
 
27
- def test_exact_pattern_success
28
- assert_equal(0,EMAIL_ADDRESS_EXACT_PATTERN=~'foo@bar.com')
29
- end
49
+ it "failure due to left chaff" do
50
+ (EmailAddressValidation::PatternExact=~'... foo@bar.com').must_equal nil
51
+ end
30
52
 
31
- def test_exact_pattern_failure_due_to_left_chaff
32
- assert_equal(nil,EMAIL_ADDRESS_EXACT_PATTERN=~'... foo@bar.com')
33
- end
53
+ it "failure due to right chaff" do
54
+ (EmailAddressValidation::PatternExact=~'foo@bar.com ...').must_equal nil
55
+ end
34
56
 
35
- def test_exact_pattern_failure_due_to_right_chaff
36
- assert_equal(nil,EMAIL_ADDRESS_EXACT_PATTERN=~'foo@bar.com ...')
37
- end
57
+ end
38
58
 
59
+ end
60
+
39
61
  end
40
62
 
metadata CHANGED
@@ -1,84 +1,79 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sixarm_ruby_email_address_validation
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
4
5
  prerelease:
5
- version: 1.2.4
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - SixArm
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain:
12
- - |
13
- -----BEGIN CERTIFICATE-----
14
- MIIDBDCCAm2gAwIBAgIJAKPwEETU5bHoMA0GCSqGSIb3DQEBBQUAMGAxCzAJBgNV
15
- BAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNp
16
- c2NvMQ8wDQYDVQQKEwZTaXhBcm0xEzARBgNVBAMTCnNpeGFybS5jb20wHhcNMTAx
17
- MjEzMjMyNzEzWhcNMTMwOTA4MjMyNzEzWjBgMQswCQYDVQQGEwJVUzETMBEGA1UE
18
- CBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEPMA0GA1UEChMG
19
- U2l4QXJtMRMwEQYDVQQDEwpzaXhhcm0uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GN
20
- ADCBiQKBgQC94mD9JDwBsunsOI0VR3CXXbOWg9cWaWciwFyJNFiM7A9I8KPLfXUw
21
- QC4czUe5ZuG4WHvinrWhkrCK+1dWBqoEClxdF/FoKO5a+tonGCjjmfy81JmFjjyx
22
- eTsjsHyvw+Qik9kpf9aj6+pnkNrVswgNHVea2o9yabbEiS6VSeJWoQIDAQABo4HF
23
- MIHCMB0GA1UdDgQWBBQzPJtqmSgc53eDN7aSzDQwr9TALDCBkgYDVR0jBIGKMIGH
24
- gBQzPJtqmSgc53eDN7aSzDQwr9TALKFkpGIwYDELMAkGA1UEBhMCVVMxEzARBgNV
25
- BAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xDzANBgNVBAoT
26
- BlNpeEFybTETMBEGA1UEAxMKc2l4YXJtLmNvbYIJAKPwEETU5bHoMAwGA1UdEwQF
27
- MAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAooEexP/oPam1TP71SyuhxMb+uTrZbSQe
28
- jVB+ExRwWadGwaNPUA56d39qwavwP+iu+3JpeonNMVvbWXF5naCX/dNFIeREHzER
29
- ZDRQYMqru9TEMna6HD9zpcstF7vwThGovlOQ+3Y6plQ4nMzipXcZ9THqs65PIL0q
30
- eabwpCbAopo=
31
- -----END CERTIFICATE-----
32
-
33
- date: 2011-07-08 00:00:00 -07:00
34
- default_executable:
11
+ cert_chain:
12
+ - !binary |-
13
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCRENDQW0yZ0F3SUJB
14
+ Z0lKQUtQd0VFVFU1YkhvTUEwR0NTcUdTSWIzRFFFQkJRVUFNR0F4Q3pBSkJn
15
+ TlYKQkFZVEFsVlRNUk13RVFZRFZRUUlFd3BEWVd4cFptOXlibWxoTVJZd0ZB
16
+ WURWUVFIRXcxVFlXNGdSbkpoYm1OcApjMk52TVE4d0RRWURWUVFLRXdaVGFY
17
+ aEJjbTB4RXpBUkJnTlZCQU1UQ25OcGVHRnliUzVqYjIwd0hoY05NVEF4Ck1q
18
+ RXpNak15TnpFeldoY05NVE13T1RBNE1qTXlOekV6V2pCZ01Rc3dDUVlEVlFR
19
+ R0V3SlZVekVUTUJFR0ExVUUKQ0JNS1EyRnNhV1p2Y201cFlURVdNQlFHQTFV
20
+ RUJ4TU5VMkZ1SUVaeVlXNWphWE5qYnpFUE1BMEdBMVVFQ2hNRwpVMmw0UVhK
21
+ dE1STXdFUVlEVlFRREV3cHphWGhoY20wdVkyOXRNSUdmTUEwR0NTcUdTSWIz
22
+ RFFFQkFRVUFBNEdOCkFEQ0JpUUtCZ1FDOTRtRDlKRHdCc3Vuc09JMFZSM0NY
23
+ WGJPV2c5Y1dhV2Npd0Z5Sk5GaU03QTlJOEtQTGZYVXcKUUM0Y3pVZTVadUc0
24
+ V0h2aW5yV2hrckNLKzFkV0Jxb0VDbHhkRi9Gb0tPNWErdG9uR0Nqam1meTgx
25
+ Sm1Gamp5eAplVHNqc0h5dncrUWlrOWtwZjlhajYrcG5rTnJWc3dnTkhWZWEy
26
+ bzl5YWJiRWlTNlZTZUpXb1FJREFRQUJvNEhGCk1JSENNQjBHQTFVZERnUVdC
27
+ QlF6UEp0cW1TZ2M1M2VETjdhU3pEUXdyOVRBTERDQmtnWURWUjBqQklHS01J
28
+ R0gKZ0JRelBKdHFtU2djNTNlRE43YVN6RFF3cjlUQUxLRmtwR0l3WURFTE1B
29
+ a0dBMVVFQmhNQ1ZWTXhFekFSQmdOVgpCQWdUQ2tOaGJHbG1iM0p1YVdFeEZq
30
+ QVVCZ05WQkFjVERWTmhiaUJHY21GdVkybHpZMjh4RHpBTkJnTlZCQW9UCkJs
31
+ TnBlRUZ5YlRFVE1CRUdBMVVFQXhNS2MybDRZWEp0TG1OdmJZSUpBS1B3RUVU
32
+ VTViSG9NQXdHQTFVZEV3UUYKTUFNQkFmOHdEUVlKS29aSWh2Y05BUUVGQlFB
33
+ RGdZRUFvb0VleFAvb1BhbTFUUDcxU3l1aHhNYit1VHJaYlNRZQpqVkIrRXhS
34
+ d1dhZEd3YU5QVUE1NmQzOXF3YXZ3UCtpdSszSnBlb25OTVZ2YldYRjVuYUNY
35
+ L2RORkllUkVIekVSClpEUlFZTXFydTlURU1uYTZIRDl6cGNzdEY3dndUaEdv
36
+ dmxPUSszWTZwbFE0bk16aXBYY1o5VEhxczY1UElMMHEKZWFid3BDYkFvcG89
37
+ Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
38
+ date: 2012-03-17 00:00:00.000000000 Z
35
39
  dependencies: []
36
-
37
40
  description:
38
41
  email: sixarm@sixarm.com
39
42
  executables: []
40
-
41
43
  extensions: []
42
-
43
44
  extra_rdoc_files: []
44
-
45
- files:
45
+ files:
46
46
  - .gemtest
47
- - CHANGELOG.txt
48
- - INSTALL.txt
49
- - LICENSE.txt
50
47
  - Rakefile
51
- - README.rdoc
48
+ - README.md
52
49
  - VERSION
53
50
  - lib/sixarm_ruby_email_address_validation.rb
54
51
  - test/sixarm_ruby_email_address_validation_test.rb
55
- has_rdoc: true
56
52
  homepage: http://sixarm.com/
57
53
  licenses: []
58
-
59
54
  post_install_message:
60
55
  rdoc_options: []
61
-
62
- require_paths:
56
+ require_paths:
63
57
  - lib
64
- required_ruby_version: !ruby/object:Gem::Requirement
58
+ required_ruby_version: !ruby/object:Gem::Requirement
65
59
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
70
- required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
65
  none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: "0"
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
76
70
  requirements: []
77
-
78
71
  rubyforge_project:
79
- rubygems_version: 1.3.9.2
72
+ rubygems_version: 1.8.11
80
73
  signing_key:
81
74
  specification_version: 3
82
- summary: "SixArm \xC2\xBB Ruby \xC2\xBB Email address validation using RFC 822 pattern match regex regular expressions"
83
- test_files:
75
+ summary: SixArm » Ruby » Email address validation using RFC 822 pattern match regex
76
+ regular expressions
77
+ test_files:
84
78
  - test/sixarm_ruby_email_address_validation_test.rb
79
+ has_rdoc: true
metadata.gz.sig CHANGED
Binary file
@@ -1,3 +0,0 @@
1
- CHANGELOG
2
- 2011-06-12 1.2.4 Rename EMAIL_ADDRESS_PATTERN to EMAIL_ADDRESS_INNER_PATTERN for clarity
3
- 2011-04-24 1.2.2 Update for Ruby 1.9.2 and Rails 3.0.6
@@ -1,32 +0,0 @@
1
-
2
- = SixArm.com Ruby Gem Install
3
-
4
-
5
- First-time users: add our gem certificate and source.
6
- When you do this once, it works for all our gems.
7
-
8
- sudo wget http://sixarm.com/sixarm.pem
9
- sudo gem cert --add sixarm.pem
10
- sudo gem sources --add http://sixarm.com
11
-
12
- Install the gem with advanced options.
13
-
14
- sudo gem install sixarm_ruby_email_address_validation --test --trust-policy HighSecurity
15
-
16
-
17
- == Notes
18
-
19
- Do you have any questions, comments, suggestions, or feedback?
20
- Let us know, we're happy to help. Our email is sixarm@sixarm.com
21
-
22
- Do you want to create your own high security gems?
23
- Learn how at http://www.rubygems.org/read/chapter/21
24
-
25
- To see your current gem certificate list:
26
-
27
- sudo gem cert --list
28
-
29
- Our cert looks like this:
30
-
31
- /C=US/ST=California/L=San Francisco/O=SixArm/CN=sixarm.com
32
-
@@ -1,12 +0,0 @@
1
- LICENSE
2
-
3
- You may choose any of these licenses:
4
-
5
- - CreativeCommons License, Non-commercial Share Alike
6
- - LGPL, GNU Lesser General Public License
7
- - MIT License
8
- - Ruby License
9
-
10
- THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
@@ -1,75 +0,0 @@
1
- = SixArm.com » Ruby » Email address validation using RFC 822 pattern matching
2
-
3
- Author:: Joel Parker Henderson, joel@joelparkerhenderson.com
4
- Copyright:: Copyright (c) 2006-2011 Joel Parker Henderson
5
- License:: See LICENSE.txt file
6
-
7
- Email address regular expression to validate an email address using RFC 822.
8
-
9
- This is a gem wrapper around http://tfletcher.com/lib/rfc822.rb
10
-
11
- Example:
12
- if EMAIL_ADDRESS_INNER_PATTERN=~'foo@bar.com'
13
- puts "found"
14
- else
15
- puts "not found"
16
- end
17
- => found
18
-
19
-
20
- == Pattern Match
21
-
22
- To find an email address in a string, do the pattern match
23
- then use the result, which is the match's string position:
24
-
25
- Example of match position:
26
- match_position = EMAIL_ADDRESS_INNER_PATTERN=~'foo@bar.com'
27
- => 0
28
-
29
- match_position = EMAIL_ADDRESS_INNER_PATTERN=~'... foo@bar.com ...'
30
- => 4
31
-
32
- match_position = EMAIL_ADDRESS_INNER_PATTERN=~'... hello world ...'
33
- => nil
34
-
35
-
36
- == Exact Pattern Match
37
-
38
- To do an exact pattern match, use the EMAIL_ADDRESS_EXACT_PATTERN.
39
- This matches the entire string from start to end; in other words,
40
- the entire string must be one email address.
41
-
42
- Example of exact pattern match:
43
- if EMAIL_ADDRESS_EXACT_PATTERN=~'foo@bar.com'
44
- puts "found"
45
- else
46
- puts "not found"
47
- end
48
- => found
49
-
50
- if EMAIL_ADDRESS_EXACT_PATTERN=~'... foo@bar.com ...'
51
- puts "found"
52
- else
53
- puts "not found"
54
- end
55
- => not found
56
-
57
- The exact pattern is especialy useful to validate an email address.
58
-
59
- Example to validate an email address:
60
- def valid?(email_address)
61
- EMAIL_ADDRESS_EXACT_PATTERN=~email_address ? true : false
62
- end
63
-
64
-
65
- == Rails Validation
66
-
67
- To add email address validation to a typical Ruby On Rails model:
68
-
69
- class User
70
- include EmailAddressValidation
71
- validates :email_address, :format => { :with => EMAIL_ADDRESS_EXACT_PATTERN },
72
- end
73
-
74
-
75
-