Last active
February 21, 2019 15:50
-
-
Save Skeiceee/9f4bbccd84b963f35ccc6357165d4a5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.ValidaRut = function() { | |
var validacion = false | |
var valor = this.val().replace(/[.]/g, '').trim() | |
valor = valor.replace('-', '') | |
var cuerpo = valor.slice(0, -1) | |
dv = valor.slice(-1).toUpperCase() | |
var m = 0, | |
s = 1; | |
for (; cuerpo; cuerpo = Math.floor(cuerpo / 10)) { | |
s = (s + cuerpo % 10 * (9 - m++ % 6)) % 11 | |
} | |
if (dv == (s ? s - 1 : 'K')) | |
validacion = true | |
return (valor === '' || valor.slice(0, -1) < 7 || isNaN(s)) ? false : validacion; | |
} | |
// No implementado | |
// Expresion regular a usar: ^0*(\d{1,3}(\.?\d{3})*)\-?([\dkK])$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.ValidaRut=function(){var a=!1,e=this.val().replace(/[.]/g,"").trim(),r=(e=e.replace("-","")).slice(0,-1);dv=e.slice(-1).toUpperCase();for(var i=0,l=1;r;r=Math.floor(r/10))l=(l+r%10*(9-i++%6))%11;return dv==(l?l-1:"K")&&(a=!0),!(""===e||e.slice(0,-1)<7||isNaN(l))&&a}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment