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.
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...
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.
···
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.
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:
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/).
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/).
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.
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
···
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:
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.
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:
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
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:
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: