Valid email address from CGI input?

J

John N. Alegre

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
 
J

Justin Collins

John said:
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
 
L

Logan Capaldo

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

rtilley

John said:
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
 
J

John N. Alegre

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
 
J

John N. Alegre

Justin,

This acutally mibht be enough.

Thanks
john

Justin said:
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
 
R

rtilley

John said:
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
 
S

Steve Peters

--r5Pyd7+fXNt84Ff3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

=20
I don't think this is possible in any language as the RFC basically says= =20
anything with an '@' in it _might_ be a vaild email address :) I think=20
there was a Perl library that attempted to do this here:
=20
http://ex-parrot.com/~pdw/Mail-RFC822-Address.html
=20
But, even it is not 100%... can you grok that RE :) I can't!
=20

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. =20

Steve Peters
(e-mail address removed)

--r5Pyd7+fXNt84Ff3
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (GNU/Linux)

iD8DBQFEDjno9T8SSoPkrKIRAtoaAKC1PM8PwxCD1UQ89R02BcpLu6xzhwCfSuUe
ep8jGtgJmft7MKDOUj5hlOo=
=8Lpj
-----END PGP SIGNATURE-----

--r5Pyd7+fXNt84Ff3--
 
J

Julian I. Kamil

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
 
R

rtilley

Steve said:
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."
 
J

Julian I. Kamil

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
 
J

John N. Alegre

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
 
J

Julian I. Kamil

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top