-
-
Save wilcorrea/bfe1e478e8fd497f3417519a1067eeb3 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
export function pis (PIS) { | |
if (PIS === '' || PIS === null) { | |
return false | |
} | |
if (String(PIS).match(/(\d)\1{9}/g)) { | |
return false | |
} | |
PIS = String(PIS).replace(/\D+/g, '') | |
const pesos = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2] | |
let soma = 0 | |
for (let i = 0; i < 10; i++) { | |
soma += pesos[i] * Number(PIS.charAt(i)) | |
} | |
soma = soma % 11 | |
soma = 11 - soma | |
soma = soma > 9 ? 0 : soma | |
return String(soma) === PIS.charAt(10) | |
} | |
export function hora (HORA) { | |
if (HORA === '' || HORA === null) { | |
return false | |
} | |
return !!String(HORA).match(/^([0-2][0-3])[0-5][0-9]+$/g) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment