views:

96

answers:

1

Hi,

I am trying to validate the format of non-negative integers with the following

validates_format_of :fundays, :with => /\A[\d]+\Z/, :message => "invalid fundays"

And here is the form field used in the view

<%= f.text_field :fundays, :maxlength => 3, :style => 'width:50px;' %>

However, when I input a non-digit into this field and submit the form, it does not fail the validation. Instead it saves a value of 0 in the database. How do I make it write to the list of error messages.

thanks

+1  A: 

validates_numericality_of :fundays, :only_integer =>true, :greater_than_or_equal_to =>0, :message => "invalid fundays"

Salil
shouldn't the above regexp also work?