Last active
October 24, 2017 12:02
-
-
Save fernandojsg/5722083 to your computer and use it in GitHub Desktop.
JS: Validar NUHSA
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
var listaNUHSAS=['AN1000038583','AN0326435212','AN0408397178','AN0404408155','AN0415331870','AN0415531870']; | |
function esNUHSAValido(nuhsa) | |
{ | |
var re = /AN\d{10}/gi; | |
if (!re.test(nuhsa)) | |
return false; | |
var b=parseInt(nuhsa.substr(2,8)); | |
var c=parseInt(nuhsa.substr(10,2)); | |
var d; | |
if (b<10000000) | |
d=b+60*10000000; | |
else | |
d=parseInt("60"+nuhsa.substr(2,8)); | |
return d%97==c; | |
} | |
for (var i=0;i<listaNUHSAS.length;i++) | |
{ | |
var nuhsa=listaNUHSAS[i]; | |
console.log(nuhsa,esNUHSAValido(nuhsa)?"Es válido":"NO ES VALIDO"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment