@emcsistemas/native-ui
Version:
Biblioteca de componentes react native
65 lines • 2.03 kB
JavaScript
export function inputMaskCEP(value) {
value = value.replace(/\D/g, '');
value = value.replace(/^(\d{5})(\d)/, '$1-$2');
return value;
}
export function inputMaskPhone(value) {
value = value.replace(/\D/g, '');
value = value.replace(/^(\d{2})(\d)/, '($1)$2');
value = value.replace(/(\d)(\d{4})$/, '$1-$2');
return value;
}
export function inputMaskCurrency(value, putSymbol) {
value = value.replace(/\D/g, '');
value = value.replace(/(\d)(\d{2})$/, '$1,$2');
value = value.replace(/(?=(\d{3})+(\D))\B/g, '.');
return putSymbol ? 'R$ ' + value : value;
}
export function inputMaskCPF(value) {
value = value.replace(/\D/g, '');
if (value.length > 11) {
value = value.substring(0, 11);
}
value = value.replace(/(\d{3})(\d)/, '$1.$2');
value = value.replace(/(\d{3})(\d)/, '$1.$2');
value = value.replace(/(\d{3})(\d{1,2})$/, '$1-$2');
return value;
}
export function inputMaskCNPJ(value) {
value = value.replace(/\D/g, '');
if (value.length > 14) {
value = value.substring(0, 14);
}
value = value.replace(/^(\d{2})(\d)/, '$1.$2');
value = value.replace(/^(\d{2})\.(\d{3})(\d)/, '$1.$2.$3');
value = value.replace(/\.(\d{3})(\d)/, '.$1/$2');
value = value.replace(/(\d{4})(\d)/, '$1-$2');
return value;
}
export function inputMaskCPFCNPJ(value) {
value = value.replace(/\D/g, '');
if (value.length > 14) {
value = value.substring(0, 14);
}
if (value.length <= 11) {
return inputMaskCPF(value);
}
else {
return inputMaskCNPJ(value);
}
}
export function inputMaskNumbers(value) {
value = value.replace(/\D/g, '');
return value;
}
export function inputMaskTime(value) {
value = value.replace(/\D/g, '');
if (value.length === 4) {
return value.replace(/^(\d{2})(\d)/, '$1:$2');
}
if (value.length === 6) {
return value.replace(/^(\d{2})(\d)(\d)/, '$1:$2:$3');
}
return value;
}
//# sourceMappingURL=util.masks.js.map