Posted by royerd on April 16, 2015 at 5:37pm
I have a form I created with an input function that looks like this:
$form['annual_income'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#title' => t("Your annual income"),
// Optional description
'#description' => t('Monthly income times 12'),
);I want the user to be able to enter a number but not with commas separating the thousands. So 2330 but not 2,330.
Can someone point me in the right direction here to add validation to this form so that it rejects numbers entered with commas and tell the user to input the number without commas?
Any help much appreciated.
Dan

Comments
Element Validation Article
http://befused.com/drupal/element-validate
This might help. Some details on element validation, with some specific rules on numeric validation.
Thanks . . . I think I ran
Thanks . . . I think I ran across this in my research. But I'll study it again.
I might also suggest that you
I might also suggest that you should just do the user a favor and strip the commas out for them; no need to throw an error!
Yes, I'd love to do that
Yes, I'd love to do that (strop the commas). I just have to read up on how to create and validate forms I guess.
Try to use jQuery to replace comma
or use $form['annual_income']['#element_validate'] = array('your_validate convert_function');
On your function to remove comma.
Thanks for the help!
Thanks for the help!