From: Kevin Brown Date: 2006-01-05T02:59:32+09:00 Subject: Re: Email address validation (was: silly regex question) On Wednesday 04 January 2006 06:25, Jeffrey Moss wrote: > I was just perfecting my email address validator, mine allows multiple > email addresses in the email_address field: > > validates_format_of :email_address, :with => > /^\s*(?:(?:[^,@\s]+)@(?:(?:[-a-z0-9]+\.)+[a-z]{2,}\s*(,\s*|\z)))+$/i, > > :allow_nil => true > > It doesn't do as careful of an inspection as yours, although I've seen > some validations that are far more detailed. It'd be nice to have some > people contribute their suggestions for the ultimate email address > validation regular expression. > > I also have this handy method in my class: > > def email_addresses > self.email_address.split(',').map{|a| a.lstrip.rstrip } > end Why do you lstrip and then rstrip? Won't a simple strip work for you? > -Jeff > > On Wed, Jan 04, 2006 at 08:27:58AM +0900, 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