you rarely want ^ or $ in validations, use \A when you mean \A

This commit is contained in:
Xavier Noria 2010-08-18 00:15:01 +02:00
parent c924068714
commit ea2ad26a8d
1 changed files with 2 additions and 2 deletions

View File

@ -28,7 +28,7 @@ module ActiveModel
# class EmailValidator < ActiveModel::EachValidator
# def validate_each(record, attribute, value)
# record.errors[attribute] << (options[:message] || "is not an email") unless
# value =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
# value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
# end
# end
#
@ -48,7 +48,7 @@ module ActiveModel
#
# class TitleValidator < ActiveModel::EachValidator
# def validate_each(record, attribute, value)
# record.errors[attribute] << "must start with 'the'" unless value =~ /^the/i
# record.errors[attribute] << "must start with 'the'" unless value =~ /\Athe/i
# end
# end
#