You are here

public function CpfService::mask in CPF 8

Returns only the digits of a CPF number.

File

src/CpfService.php, line 103

Class

CpfService
Defines the CpfService service, for CPF module.

Namespace

Drupal\cpf

Code

public function mask($value) {
  $masked_value = '';
  $digits = $this
    ->digits($value);
  if (!empty($digits)) {
    $mask = "%s%s%s.%s%s%s.%s%s%s-%s%s";
    $masked_value = vsprintf($mask, str_split($digits));
  }
  return $masked_value;
}