Valid email address from CGI input?

Is there any Ruby package that will check a input email for validity? I
want to take a submitted email address from a form and at least make the
domain is real. I would not be so much concerned in validating the
actual
user in that domain but it would be nice.

I have seen some system calls to route that can do this but I was
looking
for something more Ruby 'ish.

john

John N. Alegre wrote:

Is there any Ruby package that will check a input email for validity? I
want to take a submitted email address from a form and at least make the
domain is real. I would not be so much concerned in validating the actual
user in that domain but it would be nice.

I have seen some system calls to route that can do this but I was looking
for something more Ruby 'ish.

john

You could possibly use the socket library for simple domain
verification…

For example:

irb(main):001:0> require ‘socket’
=> true
irb(main):002:0> Socket.gethostbyname(“google.com”)
=> [“google.com”, [], 2, “H\016\317c”, “@\351\273c”, “@\351\247c”]

-Justin

On Mar 7, 2006, at 2:23 PM, John N. Alegre wrote:

for something more Ruby 'ish.

john

Yech. What if your DNS happens to be down when you “validate” the
email? Validating emails is evil in my opinion. If you want to
protect against typos, make them type it twice.

John N. Alegre wrote:

Is there any Ruby package that will check a input email for validity?

I don’t think this is possible in any language as the RFC basically says
anything with an ‘@’ in it might be a vaild email address :slight_smile: I think
there was a Perl library that attempted to do this here:

http://ex-parrot.com/~pdw/Mail-RFC822-Address.html

But, even it is not 100%… can you grok that RE :slight_smile: I can’t!

Best of Luck!
Brad

Logan

I tend to agree with you but a client is a client. He wants to send out
some stuff and only wants it to go to a valid email addy. I wanted to
do
the confirm via email like the lists do but he wont go for it. He has
the
bucks, I write the code.

Brad, That Perl thing looks like it might be the best thing going and
since
it is mostly regexps I will try a port. If I get it ill make it
available.

john

John N. Alegre wrote:

Brad, That Perl thing looks like it might be the best thing going and since
it is mostly regexps I will try a port. If I get it ill make it available.

john

Good luck with it John… I think that’s about as good as you’ll get…
and it’s pretty darn good. He has a web-based validator here that uses
the same RE:

http://mythic-beasts.com/~pdw/cgi-bin/emailvalidate

Notice his disclaimer:

Mail::RFC822::Address validates email addresses against the grammar
described in RFC 822 using regular expressions. How to validate a user
supplied email address is a FAQ (see perlfaq9): the only sure way to see
if a supplied email address is genuine is to send an email to it and see
if the user recieves it. The

Justin,

This acutally mibht be enough.

Thanks
john

On Wed, Mar 08, 2006 at 06:18:41AM +0900, rtilley wrote:

That regexp has been written and tested by some of the most knowledgible
people in the Perl world. I take it for granted that
Mail::RFC822::Address is correct.

Steve P.
[email protected]

How about this for checking the grammar:

def email_valid?(email_address)
email_address =~
/^([a-zA-Z0-9&?/!|#*$^%=~{}+'-]+|"([\x00-\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]|\\[\x00-\x7F])*")(\.([a-zA-Z0-9&_?\/!|#$^%=~{}+'-]+|"([\x00-x0C\x0E-\x21\x23-\x5B\x5D-\x7F]|\[\x00-\x7F])"))*@([a-zA-Z0-9&?/!|#*$^%=~{}+'-]+|\[([\x00-\x0C\x0E-\x5A\x5E-\x7F]|\\[\x00-\x7F])*\])(\.([a-zA-Z0-9&_?\/!|#$^%=~{}+'-]+|[([\x00-\x0C\x0E-\x5A\x5E-\x7F]|\[\x00-\x7F])]))*$/
end

To ensure that it is a working email address, I’d do email
verification. Send an email with an activation code to the address,
and ask the recipient to ‘activate’ their email registration. That’s
how email registration works in Pandora (http://pandora.rubyveil.com/).

Best regards,

Julian I. Kamil [email protected]
http://pandora.rubyveil.com/ - document publishing and web application
platform
http://books.rubyveil.com/ - The Ruby Bookshelf

How about this for checking the grammar:

def email_valid?(email_address)
email_address =~
/^([a-zA-Z0-9&?/!|#*$^%=~{}+'-]+|"([\x00-\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]|\\[\x00-\x7F])*")(\.([a-zA-Z0-9&_?\/!|#$^%=~{}+'-]+|"([\x00-x0C\x0E-\x21\x23-\x5B\x5D-\x7F]|\[\x00-\x7F])"))*@([a-zA-Z0-9&?/!|#*$^%=~{}+'-]+|\[([\x00-\x0C\x0E-\x5A\x5E-\x7F]|\\[\x00-\x7F])*\])(\.([a-zA-Z0-9&_?\/!|#$^%=~{}+'-]+|[([\x00-\x0C\x0E-\x5A\x5E-\x7F]|\[\x00-\x7F])]))*$/
end

To ensure that it is a working email address, I’d do email
verification. Send an email with an activation code to the address,
and ask the recipient to ‘activate’ their email registration. That’s
how email registration works in Pandora (http://pandora.rubyveil.com/).

Best regards,

Julian I. Kamil [email protected]
http://pandora.rubyveil.com/ - document publishing and web application
platform
http://books.rubyveil.com/ - The Ruby Bookshelf

Julian,

Sorry to look dumb I am kind of new to Ruby. I move quickly with all
the
OOP aspects of it, coming from a Java background, but the lower level
stuff, especially regex is a learning curve.

When I use this code …

def email_valid?(email_address)
    email_address =~
/^([a-zA-Z0-9&?/! #*$^%=~{}+'-]+|"([\x00-\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]|\\[\x00-\x7F])*" (\.([a-zA-Z0-9&_?\/!
#$^%=~{}+’-]+|"([\x00-x0C\x0E-\x21\x23-\x5B\x5D-\x7F]
\[\x00-\x7F])
"))*@([a-zA-Z0-9&
?/!|#*$^%=~{}+'-]+ \[([\x00-\x0C\x0E-\x5A\x5E-\x7F]|\\[\x00-\x7F])*\])(\.([a-zA-Z0-9&_?\/!
#$^%=~{}+’-]+|[([\x00-\x0C\x0E-\x5A\x5E-\x7F]|\[\x00-\x7F])]))*$/
end

in the actual code file I have the regex in one long line such as

def email_valid?(email_address)
    email_address =~ /^([a-zA-Z0-9&_?/`!|#*$^ and all the rest of the
regex
end

email_address is null after every evaluation both valid and invalid.
What
am I missing?

Is there a way in Ruby Syntax to split the regex and have Ruby ignore
the
?

Thanks for your continued help
john

Steve P. wrote:

That regexp has been written and tested by some of the most knowledgible
people in the Perl world. I take it for granted that
Mail::RFC822::Address is correct.

Yes, I agree. It’s as accurate as we’ll get. I’m not critizing it. Just
pointing out what they themselves said here:

http://www.ex-parrot.com/~pdw/Mail-RFC822-Address/Mail-RFC822-Address.html

“…the only sure way to see if a supplied email address is genuine is
to send an email to it and see if the user recieves it.”

John, from the above if there is anything missing from the
cut-and-pasted code, but I just sent you an email with an attachment
containing the email validation code used in Pandora, which you can
also download at:

http://pandora.rubyveil.com/pandora/Pandora/Project/Downloads

Take a look at it and see if you have a better luck with using that
version.

Best regards,

Julian I. Kamil [email protected]
http://pandora.rubyveil.com/ - document publishing and web application
platform
http://books.rubyveil.com/ - The Ruby Bookshelf