diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-11-20 10:51:50 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-11-20 10:51:50 +0000 |
commit | 9594832a8dd5631d924c4b45dcae9810e000b057 (patch) | |
tree | 9ca5ee22a603acfa9fd917bcb1b54794d56aad80 /activerecord/lib/active_record | |
parent | 88bd86e8bc165322cea4dfd6fecf092d7bb3d49e (diff) | |
download | rails-9594832a8dd5631d924c4b45dcae9810e000b057.tar.gz rails-9594832a8dd5631d924c4b45dcae9810e000b057.tar.bz2 rails-9594832a8dd5631d924c4b45dcae9810e000b057.zip |
validates_numericality_of uses \A \Z to ensure the entire string matches rather than ^ $ which may match one valid line of a multiline string. Closes #5716.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5589 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-x | activerecord/lib/active_record/validations.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index d7a425701b..3bc0e8fa37 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -559,9 +559,11 @@ module ActiveRecord # provided. # # class Person < ActiveRecord::Base - # validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :on => :create + # validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create # end # + # Note: use \A and \Z to match the start and end of the string, ^ and $ match the start/end of a line. + # # A regular expression must be provided or else an exception will be raised. # # Configuration options: @@ -675,7 +677,7 @@ module ActiveRecord # Validates whether the value of the specified attribute is numeric by trying to convert it to # a float with Kernel.Float (if <tt>integer</tt> is false) or applying it to the regular expression - # <tt>/^[\+\-]?\d+$/</tt> (if <tt>integer</tt> is set to true). + # <tt>/\A[\+\-]?\d+\Z/</tt> (if <tt>integer</tt> is set to true). # # class Person < ActiveRecord::Base # validates_numericality_of :value, :on => :create @@ -696,7 +698,7 @@ module ActiveRecord if configuration[:only_integer] validates_each(attr_names,configuration) do |record, attr_name,value| - record.errors.add(attr_name, configuration[:message]) unless record.send("#{attr_name}_before_type_cast").to_s =~ /^[+-]?\d+$/ + record.errors.add(attr_name, configuration[:message]) unless record.send("#{attr_name}_before_type_cast").to_s =~ /\A[+-]?\d+\Z/ end else validates_each(attr_names,configuration) do |record, attr_name,value| |