Drupal form validation functions

sultan picture sultan · Oct 23, 2010 · Viewed 14k times · Source

Is there anyway say Drupal to validate form elements like email fields, passwords, numeric fields validate automatically lets say bind a system validator

$form['email] = array(
   '#title' => t('Email'),
   '#type' => 'textfield',
   '#validate_as' => array('email', ...),
   ...
);

Answer

bbop picture bbop · Jun 11, 2012

To validate a numeric field in Drupal use:

'#element_validate' => array('element_validate_number')

No need to create a custom validation function. http://api.drupal.org/api/drupal/includes%21form.inc/function/element_validate_number/7