Custom validation of form fields?


#1

I have been looking at the many validates_* methods that we have
available and I am wondering is it possible to create a custom
validation method to be performed on a form field?

I have the following form (remote via ajax)

<%= form_remote_tag :url => {
:action => ‘do_action’,
:id => @pid },
:before => ‘Element.hide(“action_div”);’ %>
<%= text_field_tag “damt”, “0”, :size => ‘5’ %>

I would like to make sure the ‘damt’ field is submitted with only
multiples of a pre-specified amount, say for example it can only be 15,
30, 45, 60, etc

How would I go about creating a custom validates_ method to handle this,
keeping in mind this damt field does not correspond to any database
table data.

( On a side note, I tried doing this browser-side by adding a condition
=> ‘verify_amt()’ statement to the form but it broke it completely, and
then thinking maybe :condition was mispelled and should be :conditions
(plural) I tried that also and it no longer broke the form but it failed
to do anything useful… )

Thanks in advance for any help or suggestions you can offer!
-Andy