Thillai Narayanan
Thillai Narayanan

Reputation: 4886

validates_format_of :email throws error

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"

Upvotes: 0

Views: 501

Answers (1)

Vikram Jain
Vikram Jain

Reputation: 5588

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

Upvotes: 2

Related Questions