Forum: Ruby on Rails validates_format_of :email throws error

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fb6e22787531bbbd4cc3c8c63636880a?d=identicon&s=25 Lost Warrior (lostwarrior)
on 2012-10-10 16:00
(Received via mailing list)
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"
52f3528c40e9cf28ad0900886eecb128?d=identicon&s=25 Jordon Bedwell (Guest)
on 2012-10-10 16:14
(Received via mailing list)
On Wed, Oct 10, 2012 at 8:59 AM, jude <judearasu@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/?
This topic is locked and can not be replied to.