How can I add alphanumeric, numeric and email validate validation in my custom form? function form_example_form($form, &amp;$form_state) {

$form['empcode'] = array(
  '#weight' =&gt; '0',
  '#required' =&gt; '1',
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Employee Code'),
);
$form['empname'] = array(
  '#weight' =&gt; '1',
  '#required' =&gt; '1',
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Employee Name'),
);
$form['empemail'] = array(
  '#weight' =&gt; '2',
  '#required' =&gt; '0',
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Employee Email'),
);
$form['empdesignation'] = array(
  '#weight' =&gt; '3',
  '#required' =&gt; '1',
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Employee Designation'),
);
$form['mobile'] = array(
  '#weight' =&gt; '4',
  '#required' =&gt; '0',
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Mobile No.'),
);
$form['ipphone'] = array(
  '#weight' =&gt; '5',
  '#required' =&gt; '0',
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('IP Phone'),
);
$form['qualifications'] = array(
  '#weight' =&gt; '6',
  '#required' =&gt; '0',
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Qualifications'),
);
$form['profile'] = array(
  '#weight' =&gt; '7',
  '#required' =&gt; '0',
  '#type' =&gt; 'textarea',
  '#title' =&gt; t('Profile'),
);
$form['file'] = array(
  '#weight' =&gt; '8',
  '#type' =&gt; 'file',
  '#size' =&gt; '30',
  '#title' =&gt; t('Employee Photo'),
);
$form['captcha'] = array(
  '#weight' =&gt; '9',
  '#type' =&gt; 'captcha',
  '#captcha_type' =&gt; 'captcha/Math',
);
 $form['submit'] = array(
     '#weight' =&gt; '10',
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Submit'),
  );

return $form;

}


function form_example_form_validate($form, &amp;$form_state) {
  /*if (!($form_state['values']['price'] &gt; 0)){
    form_set_error('price', t('Price must be a positive number.'));
  }*/
 // print('&lt;pre&gt;'.print_r($form_state['values'],1).'&lt;/pre&gt;');
  //die();
 $file = file_save_upload('file', array(
    'file_validate_is_image' =&gt; array(),
    'file_validate_extensions' =&gt; array('png gif jpg jpeg'),
  ));
  if ($file) {
    if ($file = file_move($file, 'public://')) {
      $form_state['values']['file'] = $file;
    }
    else {
      form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
    }
  }
  else {
    form_set_error('file', t('No file was uploaded.'));
  }
}


i want to add advance level validations so that no one enter special characters to these form fields. Currently required is working.
You can use Form API Validation module for this.

It has Available Validators like "alpha_numeric" which accept only Alpha Numeric characters and for more see below image.



Just install the module and enable it in admin and then

For alphanumeric use:

'#rules' =&gt; array('alpha_numeric'),


For numeric use:

'#rules' =&gt; array('numeric'),


For email use:

'#rules' =&gt; array('email'),