Skip to content

Instantly share code, notes, and snippets.

@donpandix
Last active February 1, 2026 15:09
Show Gist options
  • Select an option

  • Save donpandix/f1d638c3a1a908be02d5 to your computer and use it in GitHub Desktop.

Select an option

Save donpandix/f1d638c3a1a908be02d5 to your computer and use it in GitHub Desktop.
Valida RUT chileno con JavaScript
var Fn = {
// Valida el rut con su cadena completa "XXXXXXXX-X"
validaRut : function (rutCompleto) {
if (!/^[0-9]+[-|‐]{1}[0-9kK]{1}$/.test( rutCompleto ))
return false;
var tmp = rutCompleto.split('-');
var digv = tmp[1];
var rut = tmp[0];
if ( digv == 'K' ) digv = 'k' ;
return (Fn.dv(rut) == digv );
},
dv : function(T){
var M=0,S=1;
for(;T;T=Math.floor(T/10))
S=(S+T%10*(9-M++%6))%11;
return S?S-1:'k';
}
}
// Uso de la función
alert( Fn.validaRut('11111111-1') ? 'Valido' : 'inválido');
@Shumma
Copy link

Shumma commented Jan 16, 2024

Agradecido con el de arriba

@paulagaldames
Copy link

gracias por el aporte, me ayudara mucho para una validacion que necesito hacer.

@hansfpc
Copy link

hansfpc commented Feb 1, 2026

super buen gist!

para ahorrarme trabajo instalo

npm i -S rut.ts

https://github.com/arrowsw/rut.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment