function number_integer_validate in Content Construction Kit (CCK) 6.3
Same name and namespace in other branches
- 6 modules/number/number.module \number_integer_validate()
- 6.2 modules/number/number.module \number_integer_validate()
FAPI validation of an individual integer element.
1 string reference to 'number_integer_validate'
- number_process in modules/
number/ number.module - Process an individual element.
File
- modules/
number/ number.module, line 531 - Defines numeric field types.
Code
function number_integer_validate($element, &$form_state) {
$field_name = $element['#field_name'];
$type_name = $element['#type_name'];
$field = content_fields($field_name, $type_name);
$field_key = $element['#columns'][0];
$value = $element['#value'][$field_key];
if ($element[$field_key]['#required'] || !empty($value)) {
$start = $value;
$value = preg_replace('@[^-0-9]@', '', $value);
if ($start != $value) {
$error_field = implode('][', $element['#parents']) . '][' . $field_key;
form_set_error($error_field, t('Only numbers are allowed in %field.', array(
'%field' => t($field['widget']['label']),
)));
}
else {
form_set_value($element[$field_key], $value, $form_state);
}
}
}