Forum: Ruby Valid email address from CGI input?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
John N. Alegre (Guest)
on 2006-03-07 21:25
(Received via mailing list)
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
Justin C. (Guest)
on 2006-03-07 22:57
(Received via mailing list)
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 C. (Guest)
on 2006-03-07 23:03
(Received via mailing list)
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.
rtilley (Guest)
on 2006-03-07 23:21
(Received via mailing list)
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-Address.html

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

Best of Luck!
Brad
John N. Alegre (Guest)
on 2006-03-08 00:40
(Received via mailing list)
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 (Guest)
on 2006-03-08 00:44
(Received via mailing list)
Justin,

This acutally mibht be enough.

Thanks
john
rtilley (Guest)
on 2006-03-08 02:14
(Received via mailing list)
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
Steve P. (Guest)
on 2006-03-08 03:57
(Received via mailing list)
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.
removed_email_address@domain.invalid
Julian I. Kamil (Guest)
on 2006-03-08 04:09
(Received via mailing list)
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 <removed_email_address@domain.invalid>
http://pandora.rubyveil.com/ - document publishing and web application
platform
http://books.rubyveil.com/ - The Ruby Bookshelf
rtilley (Guest)
on 2006-03-08 04:15
(Received via mailing list)
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/...

"...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 I. Kamil (Guest)
on 2006-03-08 04:36
(Received via mailing list)
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 <removed_email_address@domain.invalid>
http://pandora.rubyveil.com/ - document publishing and web application
platform
http://books.rubyveil.com/ - The Ruby Bookshelf
John N. Alegre (Guest)
on 2006-03-08 17:29
(Received via mailing list)
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
<cr>?

Thanks for your continued help
john
Julian I. Kamil (Guest)
on 2006-03-08 17:50
(Received via mailing list)
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/Projec...

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

Best regards,

Julian I. Kamil <removed_email_address@domain.invalid>
http://pandora.rubyveil.com/ - document publishing and web application
platform
http://books.rubyveil.com/ - The Ruby Bookshelf
This topic is locked and can not be replied to.