function form_validate_integer in Form Builder 7
Same name and namespace in other branches
- 6 form_builder.module \form_validate_integer()
- 7.2 form_builder.module \form_validate_integer()
Generic validation function to check that an element has a integer value.
3 string references to 'form_validate_integer'
- FormBuilderWebformFormTest::testConfigurationForm in modules/
webform/ tests/ FormBuilderWebformFormTest.php - form_builder_property_maxlength_form in includes/
form_builder.properties.inc - Configuration form for the "maxlength" property.
- form_builder_property_size_form in includes/
form_builder.properties.inc - Configuration form for the "size" property.
File
- ./
form_builder.module, line 350 - form_builder.module Generic form building framework and user interface.
Code
function form_validate_integer(&$element, &$form_state) {
$value = $element['#value'];
if (empty($value)) {
return;
}
// Remove thousands separators from numbers.
$locale_info = localeconv();
$separator = empty($locale_info['thousands_sep']) ? ',' : $locale_info['thousands_sep'];
$new_value = str_replace(array(
' ',
$separator,
), '', $value);
$int_value = $new_value * 1;
$new_value = (string) $int_value;
if (!is_int($int_value) || $int_value === 0) {
form_error($element, t('The %title field value must be an integer.', array(
'%title' => $element['#title'],
)));
}
elseif ($new_value !== $value) {
form_set_value($element, $new_value, $form_state);
}
}