From: "Andreas S." Date: 2006-01-04T21:47:34+09:00 Subject: Re: Email Address Regex Jacob Fugal wrote: > On 1/3/06, Dan Kohn 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])*\]))*$/ It is trivial to create a formally correct address that makes absolutely no sense, so what's the point of doing such a complicated and error-prone validation? -- Posted via http://www.ruby-forum.com/.