From 9594832a8dd5631d924c4b45dcae9810e000b057 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 20 Nov 2006 10:51:50 +0000 Subject: 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 --- activerecord/lib/active_record/validations.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'activerecord/lib') 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 integer is false) or applying it to the regular expression - # /^[\+\-]?\d+$/ (if integer is set to true). + # /\A[\+\-]?\d+\Z/ (if integer 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| -- cgit v1.2.3