function _br_tax_number_fields_is_number in Brazilian IDs 7
Helper function for checking if the entered value contains only numbers.
Parameters
Array $element: The form element array.
Array $form_state_values: The $form_state['values'] array.
Return value
String The trimmed value entered by the user.
3 calls to _br_tax_number_fields_is_number()
- br_tax_number_fields_cnpj_cpf_validate in ./
br_tax_number_fields.module - Validation callback.
- br_tax_number_fields_cnpj_validate in ./
br_tax_number_fields.module - Validation callback.
- br_tax_number_fields_cpf_validate in ./
br_tax_number_fields.module - Validation callback.
File
- ./
br_tax_number_fields.module, line 322 - Adds Brazilian Tax Number field widgets to text field type at the Field UI and creates new form element types for use in the Form API.
Code
function _br_tax_number_fields_is_number($element, &$form_state_values) {
$value = trim($element['#value']);
$value = str_replace(array(
'.',
'-',
'/',
), '', $value);
// The value of $depth_pointer will end up being, in most cases, something
// like: [group][field_name][un][0][value]
$depth_pointer = '';
foreach ($element['#parents'] as $parent) {
$depth_pointer .= "['{$parent}']";
}
// Set the clean value for $form_state[group][field_name][un][0][value]
// which will be saved into the database.
eval("\$form_state_values" . $depth_pointer . " = \$value;");
if (strlen($value) != strlen(preg_replace('/[^0-9]+/', '', $value))) {
form_error($element, t('%name must have only numbers.', array(
'%name' => $element['#title'],
)));
}
return $value;
}