validates_format_of :email throws error

15 views
Skip to first unread message

jude

unread,
Oct 10, 2012, 9:59:48 AM10/10/12
to rubyonra...@googlegroups.com

Validates_format_of :email example available on api.rubyonrails.org is throwing errors.

class Person < ActiveRecord::Base validates_format_of :email, :with => %r\A([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})\Z/, :on => :create end

validates :email, :format => { :with => %r\A([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})\Z/, :on => :create }

Currently i am using rails 3.2.8 versions.

On loading getting the error as "syntax error, unexpected ']', expecting keyword_end"

Jordon Bedwell

unread,
Oct 10, 2012, 10:12:47 AM10/10/12
to rubyonra...@googlegroups.com
On Wed, Oct 10, 2012 at 8:59 AM, jude <jude...@gmail.com> wrote:
> class Person < ActiveRecord::Base validates_format_of :email, :with =>
> %r\A([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})\Z/, :on => :create end

> validates :email, :format => { :with =>
> %r\A([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})\Z/, :on => :create }

%r\A([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})\Z/
%r\A\Z/
%r/

Maybe use %r!! instead of %r/?
Reply all
Reply to author
Forward
0 new messages