On 1/3/06, Dan Kohn <dan / dankohn.com> wrote:
> Here's a rails example for validating email addresses.
>
>   validates_format_of :login, :with => /
>     ^[-^!$#%&'*+\/=?`{|}~.\w]+
>     @[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])*
>     (\.[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])*)+$/x,
>     :message => "must be a valid email address",
>     :on => :create

Be careful with email validation via regex, it's harder than you might
think[1][2]:

/^([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])*\]))*$/

Jacob Fugal

[1] From http://phantom.byu.edu/pipermail/uug-list/2004-January/009707.html
[2] That regex needs some serious /x treatment, which I didn't know
about at the time it was written.