# RFC2822::EmailAddress

**URL:** <https://www.ruby-forum.com/t/rfc2822-emailaddress/82096>\
**Category:** Ruby\
**Created:** [January 17, 2007, 12:01pm UTC](https://www.ruby-forum.com/t/rfc2822-emailaddress/82096 "2007-01-17T12:01:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josselin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Josselin](https://www.ruby-forum.com/u/Josselin)\
**Post date:** [January 17, 2007, 12:01pm UTC](https://www.ruby-forum.com/t/rfc2822-emailaddress/82096/1 "2007-01-17T12:01:51Z")

</div>

I am checking email addresses using RFC2822::EmailAddress

address =~ RFC2822::EmailAddress

seems to work fine, but I wonder why an email address like :  
me@somewhere is accepeted… there is no domain

is it right ?

tfyl

joss

---

<div class="post-metadata">

**Author:** ![Josselin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Josselin](https://www.ruby-forum.com/u/Josselin)\
**Post date:** [January 17, 2007, 12:51pm UTC](https://www.ruby-forum.com/t/rfc2822-emailaddress/82096/2 "2007-01-17T12:51:09Z")

</div>

On Wed, 17 Jan 2007, Josselin wrote:

> I am checking email addresses using RFC2822::EmailAddress
> 
> address =~ RFC2822::EmailAddress
> 
> seems to work fine, but I wonder why an email address like : me@somewhere is  
> accepeted… there is no domain
> 
> is it right ?

it could still be ‘me@somehost’ - and as long as your mail service can  
resolve that address, it’s perfectly fine… When you perform the regexp  
check therefore, this address is fine - the regexp check can’t see  
whether  
the user, host, or domain are valid - but the format is OK.

Benedikt

ALLIANCE, n. In international politics, the union of two thieves who  
have their hands so deeply inserted in each other’s pockets that  
they cannot separately plunder a third.  
(Ambrose Bierce, The Devil’s Dictionary)

---

<div class="post-metadata">

**Author:** ![Josselin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Josselin](https://www.ruby-forum.com/u/Josselin)\
**Post date:** [January 17, 2007, 2:56pm UTC](https://www.ruby-forum.com/t/rfc2822-emailaddress/82096/3 "2007-01-17T14:56:23Z")

</div>

…excuse me…but…how do i load this module or is it a constant???  
dave

Josselin wrote:

> On 2007-01-17 12:50:22 +0100, Benedikt H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> said:
> 
> > ALLIANCE, n. In international politics, the union of two thieves who  
> > have their hands so deeply inserted in each other’s pockets that  
> > they cannot separately plunder a third.  
> > (Ambrose Bierce, The Devil’s Dictionary)
> 
> thanks a lot

---

<div class="post-metadata">

**Author:** ![Josselin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Josselin](https://www.ruby-forum.com/u/Josselin)\
**Post date:** [January 17, 2007, 2:06pm UTC](https://www.ruby-forum.com/t/rfc2822-emailaddress/82096/4 "2007-01-17T14:06:26Z")

</div>

On 2007-01-17 12:50:22 +0100, Benedikt H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
said:

> ALLIANCE, n. In international politics, the union of two thieves who  
> have their hands so deeply inserted in each other’s pockets that  
> they cannot separately plunder a third.  
> (Ambrose Bierce, The Devil’s Dictionary)

thanks a lot

---

<div class="post-metadata">

**Author:** ![Josselin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Josselin](https://www.ruby-forum.com/u/Josselin)\
**Post date:** [January 17, 2007, 4:38pm UTC](https://www.ruby-forum.com/t/rfc2822-emailaddress/82096/5 "2007-01-17T16:38:08Z")

</div>

On Wed, 17 Jan 2007 22:56:26 +0900  
Dave R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> …excuse me…but…how do i load this module or is it a constant???  
> dave

## – module RFC822 EmailAddress = begin qtext = ‘[^\x0d\x22\x5c\x80-\xff]’ dtext = ‘[^\x0d\x5b-\x5d\x80-\xff]’ atom = ‘[^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-’ + ‘\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+’ quoted\_pair = ‘\x5c[\x00-\x7f]’ domain\_literal = “\x5b(?:#{dtext}|#{quoted\_pair})_\x5d" quoted\_string = "\x22(?:#{qtext}|#{quoted\_pair})_\x22” domain\_ref = atom sub\_domain = “(?:#{domain\_ref}|#{domain\_literal})” word = “(?:#{atom}|#{quoted\_string})” domain = “#{sub\_domain}(?:\x2e#{sub\_domain})_" local\_part = "#{word}(?:\x2e#{word})_” addr\_spec = “#{local\_part}\x40#{domain}” pattern = /\A#{addr\_spec}\z/ end end

In your program. On in a file of its own and require ‘rfc822.rb’

Dom
