# Custom validation of form fields?

**URL:** <https://www.ruby-forum.com/t/custom-validation-of-form-fields/57773>\
**Category:** Rails\
**Created:** [April 13, 2006, 10:24pm UTC](https://www.ruby-forum.com/t/custom-validation-of-form-fields/57773 "2006-04-13T22:24:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [April 13, 2006, 10:24pm UTC](https://www.ruby-forum.com/t/custom-validation-of-form-fields/57773/1 "2006-04-13T22:24:21Z")

</div>

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
