You are here

public function BrazilianIdsService::formatCnpj in Brazilian IDs 8

Formats a CNPJ number like 99.999.999/9999-99.

Parameters

string $value: The CNPJ number to be formatted.

Return value

string The formatted CNPJ number.

Overrides BrazilianIdsServiceInterface::formatCnpj

1 call to BrazilianIdsService::formatCnpj()
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 158

Class

BrazilianIdsService
Provides validation functionalities for Brazilian IDs numbers.

Namespace

Drupal\brazilian_ids

Code

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