Custom form validation I've created a custom module for populating a database and now I need to apply form validation to this form.

I want a few different validation things to happen.


I want to limit specific entries on the client side IE: only allowing 6 characters being entered etc.
On submit I want to run through validation rules to make sure what was entered is correct. IE: only positive #s etc.


Are there any drupal 7 FAPI fields to validate specifics like this? 

I found something like '#element_validate' =&gt; array('element_validate_integer_positive'),

Is there a list anywhere of element validations like this? I'm unable to find documentation anywhere :(
I assume you are using Drupal's Form API.


  
  I want to limit specific entries on the client side IE: only allowing 6 characters being entered etc.
  


In your element definition, you need to add the HTML attribute maxlength. For example:

$form['your_field_name']['#attributes'] = array('maxlength' =&gt; array('6'));  

Regarding:


  
  On submit I want to run through validation rules to make sure what was entered is correct. IE: only positive #s etc.
  


You can create your own validation function for the form or the element. For example, in your form definition, in the element you want to validate, you need to enter:

$form['your_field_name']['#element_validate'] = array('your_field_name_validate');

In this case, your_field_name_validate is the name of the function that will be invoked when the form is submitted. The function needs to be in the same module as the form definition, or in an include file. See an example here. Pasting:

function my_field_name_validate($element, &amp;$form_state, $form) {
   if (empty($element['#value'])) {
     form_error($element, t('This field is required.'));
   }
}