fix rut bug when using backspace

This commit is contained in:
Chris Cromer 2022-01-07 17:16:17 -03:00
parent 17c6278997
commit 6e39f6170d
Signed by: cromer
GPG Key ID: FA91071797BEEEC2

View File

@ -72,7 +72,7 @@ export default function AgendarComponent() {
}; };
const handleRutChange = (event) => { const handleRutChange = (event) => {
let value = event.target.value.replace(/\./g, '').replace('-', ''); let value = Rut.limpiar(event.target.value);
if (value.match(/[^0-9k]/ig)) { if (value.match(/[^0-9k]/ig)) {
value = value.replace(value, ''); value = value.replace(value, '');
} }
@ -88,6 +88,15 @@ export default function AgendarComponent() {
else if (value.match(/^(\d)(\d{0,2})$/)) { else if (value.match(/^(\d)(\d{0,2})$/)) {
value = value.replace(/^(\d)(\d{0,2})$/, '$1.$2'); value = value.replace(/^(\d)(\d{0,2})$/, '$1.$2');
} }
if (value.substr(value.length - 1, 1) === '-') {
value = value.substr(0, value.length - 1);
}
if (value.substr(value.length - 1, 1) === '.') {
value = value.substr(0, value.length - 1);
}
setRut(value); setRut(value);
} }