[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Valid email address from CGI input?

John N. Alegre

3/7/2006 7:20:00 PM

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

12 Answers

Justin Collins

3/7/2006 8:55:00 PM

0

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


Logan Capaldo

3/7/2006 9:03:00 PM

0


On Mar 7, 2006, at 2:23 PM, 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
>
>

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.


Brad Tilley

3/7/2006 9:17:00 PM

0

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 :) I think
there was a Perl library that attempted to do this here:

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

But, even it is not 100%... can you grok that RE :) I can't!

Best of Luck!
Brad

John N. Alegre

3/7/2006 10:38:00 PM

0

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

Logan Capaldo wrote:

> 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

3/7/2006 10:39:00 PM

0

Justin,

This acutally mibht be enough.

Thanks
john

Justin Collins wrote:

> 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

Brad Tilley

3/8/2006 12:13:00 AM

0

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/ema...

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


Steve Peters

3/8/2006 1:57:00 AM

0

On Wed, Mar 08, 2006 at 06:18:41AM +0900, rtilley wrote:
> 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 :) I think
> there was a Perl library that attempted to do this here:
>
> http://ex-parrot.com/~pdw/Mail-RFC822-Ad...
>
> But, even it is not 100%... can you grok that RE :) I can't!
>

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 Peters
steve@fisharerojo.org

julian.kamil@gmail.com

3/8/2006 2:06:00 AM

0

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.rub...).

Best regards,

Julian I. Kamil <julian.kamil@gmail.com>
http://pandora.rub... - document publishing and web application
platform
http://books.rub... - The Ruby Bookshelf

Brad Tilley

3/8/2006 2:12:00 AM

0

Steve Peters 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-Ad...

"...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."

julian.kamil@gmail.com

3/8/2006 2:29:00 AM

0

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.rub...).

Best regards,

Julian I. Kamil <julian.kamil@gmail.com>
http://pandora.rub... - document publishing and web application
platform
http://books.rub... - The Ruby Bookshelf