You are here

public function BrazilianIdsService::formatCpf in Brazilian IDs 8

Formats a CPF number like 999.999.999-99.

Parameters

string $value: The CPF number to be formatted.

Return value

string The formatted CPF number.

Overrides BrazilianIdsServiceInterface::formatCpf

1 call to BrazilianIdsService::formatCpf()
BrazilianIdsService::formatCpfCnpj in src/BrazilianIdsService.php
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.

File

src/BrazilianIdsService.php, line 148

Class

BrazilianIdsService
Provides validation functionalities for Brazilian IDs numbers.

Namespace

Drupal\brazilian_ids

Code

public function formatCpf($value) {
  if (preg_match('/^[0-9]{11}$/', $value)) {
    $value = vsprintf('%s%s%s.%s%s%s.%s%s%s-%s%s', str_split($value));
  }
  return $value;
}