pls. replace this line:
$items[$delta]['value'] = preg_replace('@[^-0-9\.]@', '', $items[$delta]['value']);
with this one:
$items[$delta]['value'] = preg_replace('@[^-0-9\.]@', '', $items[$delta]['value']);
if($item['value'] != $items[$delta]['value'] /*&& empty($items[$delta]['value'])*/){
form_set_error($field['field_name'], t('Illegal value for %name.', array('%name' => t($field['widget']['label']))));
}

Because now if I put chars into the number field, the number modul convert it to empty string, and this way its possible to submit required number field with 0 value without error, and the lesser, greater rules is ignored in this case.

sorry my english.

Tyrael

Comments

Tyrael’s picture

pls. replace this line:

$items[$delta]['value'] = preg_replace('@[^-0-9\.]@', '', $items[$delta]['value']);

with this one:

$items[$delta]['value'] = preg_replace('@[^-0-9\.]@', '', $items[$delta]['value']);
if($item['value'] != $items[$delta]['value'] /*&& empty($items[$delta]['value'])*/){
  form_set_error($field['field_name'], t('Illegal value for %name.', array('%name' => t($field['widget']['label']))));
}
binford2k’s picture

I would actually prefer an option to allow text in a numeric field.

David Stosik’s picture

Version: 5.x-1.4 » 5.x-1.6-1

Hello,
That is a very good idea, and I don't see why nobody has needed this before.
Currently, there's no validation on number input fields. So the user inputs what he wants, and is not warned of any problem, where Drupal will convert, blindly, the string to a 0 integer value.
For me, it is not very user friendly, so there should be at least an administer option to choose whether or not to check number when validating form.

Thank you for reading me,
David

rvarkonyi’s picture

This should definitely go into the module! Thanks for the code!

Rob

karens’s picture

Status: Needs review » Closed (won't fix)

Too old now, way past the time when we will add features to D5 version. Sorry this never got addressed.

kenorb’s picture

Status: Closed (won't fix) » Closed (duplicate)