Skip to main content

AddToAny

Share/Save

PHP

How to do Numeric Validation in Drupal Webforms

I spent a lot of time to figure out How to restrict only numeric data in drupal webforms. To my surprise drupal does'nt provide such functionality. But we can achieve it through Additional Validation in Webform Advanced Settings.

Just write this PHP code in additional validation.

  $mobile_no = $form_values['submitted_tree']['mobile_no'];
  if (strlen(trim($mobile_no)) > 0){
    if (!is_numeric($mobile_no)) {
      form_set_error('submitted][mobile_no', t('Mobile No. must be Numeric'));
    }
  }
Syndicate content