From: Dominik Honnef Date: 2008-02-01T02:12:31+09:00 Subject: Re: validate email address? On [Fri, 01.02.2008 01:14], Eric H. wrote: > Anyone have a code snippet that tells whether an email address is > "valid" but not necessarily whether it is a working address because that > much I can sort out through my mail server through any bounces. > > I have a database of addresses where the person entering the data has a > bad, bad, bad, BAD habit of not validating them before entering them and > so I get things like "***DO NOT SHARE DATA***" and "lmnopaol.com" and > the like. It's not my company or else she'd be going over all the > entries by hand. > > Thanks in advance email = "email@host.tld" email2 = "email@h@ost.tld" email =~ /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i #=> true/0 email2 =~ /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i #=> nil/false I hope that helped. (That strange looking thing is called a regular expression) -- Dominik Honnef