Submitted by vaibhav on Sat, 10/10/2009 - 11:13
Posted in
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')); } }
Replace mobile_no with your "Field Key" of the component you want to validate
Thanks
Thanks for this great information. You save me a lot of time.
@Nikhil
My pleasure.
Thanks. Can you provide more
Thanks. Can you provide more information. If you can attach some snapshots, it would be great
The field module has a
The field module has a function for this: _element_validate_number, so you can do:
Sorry, I made a mistake, the
Sorry, I made a mistake,
the validate functions should be in an array, so the code looks like:
How do I implement this?
This is awesome Jelle,
I am a noob and wonder how I can implement this into a form. Where does the code go?
Thanks a lot
Thanks a lot for this code snippet! :)
than ks a lot
It solve my problem thanks a lot sir
Post new comment