public static function Cpf::validateCpf in CPF 8
Same name and namespace in other branches
- 8.2 src/Element/Cpf.php \Drupal\cpf\Element\Cpf::validateCpf()
Form element validation handler for #type 'cpf'.
Note that #maxlength and #required is validated by _form_validate() already.
File
- src/
Element/ Cpf.php, line 80
Class
- Cpf
- Provides a form input element for entering an CPF number.
Namespace
Drupal\cpf\ElementCode
public static function validateCpf(&$element, FormStateInterface $form_state, &$complete_form) {
$value = trim($element['#value']);
$form_state
->setValueForElement($element, $value);
if ($value !== '' && !\Drupal::service('cpf')
->isValid($value)) {
$form_state
->setError($element, t('The CPF number %cpf is not valid.', [
'%cpf' => $value,
]));
}
}