@ciebit/mascara-telefone
Version:
Módulo para aplicação de máscara a telefones com 10 e 11 digitos
22 lines (17 loc) • 570 B
text/typescript
import { Mascara } from "@ciebit/mascaras/src/Mascara";
export class Telefone implements Mascara
{
public mascarar(telefone:string): string
{
if (! telefone) {
return '';
}
let numero = telefone.replace(/\D/g, '');
if (numero.length == 0) {
return '';
} else if (numero.length >= 11) {
return '('+ numero.substr(0,2) +') ' + numero.substr(2,5) + '-'+ numero.substr(7,4);
}
return '('+ numero.substr(0,2) +') ' + numero.substr(2,4) + '-'+ numero.substr(6,4);
}
}