search for: validates_numericality_of

Displaying 20 results from an estimated 77 matches for "validates_numericality_of".

2006 Jan 19
7
validates_numericality_of positive integer
Hi, What is the simplest way to validate a positive integer? validates_numericality_of :foo, :integer_only => true how do I add the positive part? Do I need another validation statement for pattern matching or do I have to write a validate() funciton for my model? Thanks, Peter
2006 Apr 03
4
validates_numericality_of, :allow_nil => true?
Is there a way to use validates_numericality_of and still allow null values? I have a model with some optional values that can be nil, but if they''re present, they must be numbers. Will I need to construct a custom valiation for this, or is there some method built in? Seems like it would be a common enough need. Jeff -- Posted...
2008 Apr 04
6
validates_numericality_of :not_equal_to
I have a situation in which I want to validate a number is not zero. Both positive and negative values are acceptable, just not zero. validates_numericality_of has an :equal_to attribute, but I don''t see a :not_equal_to. I have not yet been able to find anyone who has discussed this. I did find information about custom validators, so I am now using a custom validator to check the field and add an appropriate error message. Is there an easier w...
2008 May 11
0
validates_numericality_of and greater_than* doesn't appear to be working
I''m using Rails 2.0.2 and I have been trying to take advantage of the "validates_numericality_of" with the ":greater_than" option with something like this: validates_numericality_of :users, :greater_than => 0, :only_integer => true, :allow_nil => true, :message => "The number of allowed users must be a whole number greater than zero." But this doesn'&...
2008 Mar 28
0
Patch review request: validates_numericality_of does not replace option in custom message like in default message
Hi, Today someone created a ticket for a defect in validates_numericality_of, at first sight i thought it wasn''t a defect but an enhancement. But then i found that validates_length_of accepts :message => "should be greater than %d", but validates_numericality_of doesn''t (The output for v_n_o is: "should be greater than %d" instead of...
2008 Feb 12
0
Validate all model fields with validates_numericality_of
hi, I have a rather big table and i need to validate every decimal field in the table to make sure its numeric. Can anyone think of the best way to do this or is it even possible? I dont want to write validates_numericality_of: and then each field in the table seperately. JB -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to r...
2006 May 31
1
ActiveRecord: When / where to validate data? Tricky question
First of all, thanks for you time. I have kind of a tricky question and wanted to see what you guys thought. ------------------------------------------- Lets say I have this: ------------------------------------------- class Purchase < ActiveRecord::Base validates_numericality_of :some_number, :only_integer => true end ------------------------------------------- Then I do this: ------------------------------------------- purchase = Purchase.new purchase.some_number = ''This is not a number'' Right now the data is not correct. Is this ok? Why should I ev...
2008 May 17
12
validates_numericality_of with greater_than* less_than* simply don't work
It seems that the validations for: greater_than greater_than_or_equal_to less_than less_than_or_equal_to equal_to odd even Simply do not work (Rails 2.0.2). I''ve tried every combination I can think of and these never seem to fire. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails:
2005 Aug 21
8
validates_numericality_of
As far as I can tell "numericality" is not a word. Maybe this method should be renamed. -- R. Mark Volkmann Partner, Object Computing, Inc.
2007 Nov 03
3
Birthdate validation
...to validate it writing this code on my user.rb fil at app/ models class User < ActiveRecord::Base validates_presence_of :full_name validates_presence_of :street_address validates_presence_of :city validates_presence_of :state validates_presence_of :country validates_presence_of :zip_code validates_numericality_of :zip_code, :message => "must contain only numbers." validates_presence_of :phone validates_numericality_of :phone, :message => "must contain only numbers." validates_presence_of :email validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a- z]{2,})$/i...
2009 Jun 24
2
At my wits end ! Controlling passed in negative values from a form
Hi, I am trying to validate a numeric value passed in from a form, which is saved in a MySQL db as decimal(9,2) Now problem is I need to ensure people don''t enter a form value like -. 003. In my validations, I have a validates_numericality_of check being done. Furthermore, in validate method, I have a check using an if statement such as : ((an_object[n].nil? or an_object[n] < 0) and !an_object[n].blank?) While testing, Rails validation can catch -0.003. However, it just does not catch -.003 (without leading zero). In fact, in case...
2011 Jun 19
10
validates_numercality_of with allow_nil.
In the model I have: validates :square_meters_public_land, :barrier_meters, :numericality => { :greater_than_or_equal_to => 0 }, :allow_nil => true but if, in the field, on create, I don''t insert a value I have the error "field is not a number". -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To
2006 Aug 14
1
What fields_for really for?
Hello everyone! I have 3 models: === 1 === class Region < ActiveRecord::Base has_many :districts end === 2 === class District < ActiveRecord::Base belongs_to :region has_many :suburbs end === 3 === class Suburb < ActiveRecord::Base belongs_to :district validates_numericality_of :region_id, :only_integer => true end In edit.rhtml for SuburbController I need to specify region_id. There is no region_id in suburb model so first I added these lines to it: ... class Suburb < ActiveRecord::Base belongs_to :district attr_writer :region_id def region_id district....
2006 Jun 21
3
validation help
I would like to validate a number within a certain range. To first test that a entry is a valid number i use validates_numericality_of :my_number, :message =>''sorry, not a number'' to test if the number is within a certain range i use validates_inclusion of :my_number, :in => min..max, message => ''outside range!'' If the numericality test fails, I don''t want to do the second r...
2007 Jan 18
2
Conditional validates_inclusion_of execution problem
All, I have a field that I''m validating with validates_numericality_of on as well as validates_inclusion_of, like so: validates_numericality_of :number_of_owners, :only_integer => true, :message => ''must be a whole number'' validates_inclusion_of :number_of_owners, :in...
2010 Feb 10
6
validation problems
Hi, there. I have two validations in the model: validates_numericality_of :value, :only_integer=>true, :allow_blank=>true validates_size_of :value, :is=>9, :message=>"must be 5-digit number", :if=>Proc.new{|u| u.value.is_a?(Numeric)} They work as expected except when the :value is character/string like "a" "abc", the second v...
2006 Jun 19
3
newbie validation
hi there. Here is the simple scenario: My active record connects to a table that contains an integer field. My form contains a text box that allows me to enter a value to get updated to the integer field. If anything gets entered that is anything other than a POSITIVE INTEGER, I want to display an error. I have noticed that if I create a new active record like @record =
2006 May 22
4
How to check an input String is a number or not in ruby?
How to check an input String is a number or not in ruby? Thanks in advance, Joshua -- Posted via http://www.ruby-forum.com/.
2006 Jun 07
1
Validating numericality based on related attribute value?
...e a price attribute in my model which I need to validate as a positive number if the attribute price_terms.requires_value is equal to ''Y'', otherwise price can be blank or zero. Price_terms is a select list which my model table belongs_to. How do I do this? - I tried doing this: validates_numericality_of :price, :if => self.price_term.requires_value.upcase == ''Y'' But that doesn''t work... Thanks in advance, Matt.
2006 Jul 24
6
error_messages_for not working
...require "digest/sha1" class User < ActiveRecord::Base validates_presence_of :eaddress, :fname, :passwd, :pcode, :country, :day, :year, :month, :gender, :agreement validates_confirmation_of :passwd validates_uniqueness_of :eaddress validates_length_of :eaddress, :within => 6..255 validates_numericality_of :pcode end View: index.rhtml ... <table class="compbox" cellpadding="0" cellspacing="0"> <tr><td class="panelheader">Quick Register!</td></tr> <tr valign="top" align="left"> <td class="login...