public function BrazilianIdsService::formatCpfCnpj in Brazilian IDs 8
Formats a CPF number like 999.999.999-99 or a CNPJ number like 99.999.999/9999-99 depending on the number of digits.
Parameters
string $value: The CPF or CNPJ number to be formatted.
Return value
string The formatted CPF or CNPJ number.
Overrides BrazilianIdsServiceInterface::formatCpfCnpj
File
- src/
BrazilianIdsService.php, line 168
Class
- BrazilianIdsService
- Provides validation functionalities for Brazilian IDs numbers.
Namespace
Drupal\brazilian_idsCode
public function formatCpfCnpj($value) {
// Formats as CPF or CNPJ depending on the number of digits.
if (preg_match('/^[0-9]{11}$/', $value)) {
// CPF number.
$value = $this
->formatCpf($value);
}
elseif (preg_match('/^[0-9]{14}$/', $value)) {
// CNPJ number.
$value = $this
->formatCnpj($value);
}
return $value;
}