Use hook_form_alter() to apply custom validation to drupal
create a module, for example. Mymodule
file mymodule.module
function mymodule_form_alter(&$form, &$form_state, $form_id) { print $form_id; if($form_id=='webform_client_form_1') //Change webform id according to you webformid { $form['#validate'][]='mymodule_form_validate'; return $form; } } function mymodule_form_validate($form,&$form_state) { //where "phone" is field name of webform phone field $phoneval = $form_state['values']['submitted']['phone']; if($phoneval=='') { form_set_error('phone','Please fill the form field'); } // Then use regular expression to validate it. // In above example i have check if phonefield is empty or not. }
If you want to describe in more detail how to use hook_form_alter() , follow this link http://www.codeinsects.com/drupal-hook-system-part-2.html
Allex
source share