rails validate_format_of non-negative integers
Posted
by ash34
on Stack Overflow
See other posts from Stack Overflow
or by ash34
Published on 2010-04-01T06:09:05Z
Indexed on
2010/04/01
6:13 UTC
Read the original article
Hit count: 311
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
© Stack Overflow or respective owner