Created
February 1, 2018 11:12
-
-
Save tiagomatos/73b4166069d59e44906255edef498392 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<script type="text/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'; | |
} | |
} | |
$("#checkout").on("submit", function(){ | |
if($("#order_other_boleta_o_factura option:selected").val() == "Factura Electrónica"){ | |
var tax_id = $("#order_billing_address_taxid").val(); | |
if(!Fn.validaRut(tax_id)){ alert('RUT Inválido.'); } | |
return Fn.validaRut(tax_id); | |
} | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment