function bigint_field_widget_validate in Big Integer 7
FAPI validation of an individual number element.
1 string reference to 'bigint_field_widget_validate'
- bigint_field_widget_form in ./
bigint.module - Implements hook_field_widget_form().
File
- ./
bigint.module, line 294 - Defines numeric field types.
Code
function bigint_field_widget_validate($element, &$form_state) {
$field = field_widget_field($element, $form_state);
$instance = field_widget_instance($element, $form_state);
$type = $element['#number_type'];
$value = $element['#value'];
// Reject invalid characters.
if (!empty($value)) {
switch ($type) {
case 'bigint':
$regexp = '@([^-0-9])|(.-)@';
$message = t('Only numbers are allowed in %field.', array(
'%field' => $instance['label'],
));
break;
}
if ($value != preg_replace($regexp, '', $value)) {
form_error($element, $message);
}
else {
form_set_value($element, $value, $form_state);
}
}
}