Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Forked from hamiltongabriel/123123
Created March 14, 2018 14:09
Show Gist options
  • Save wilcorrea/bfe1e478e8fd497f3417519a1067eeb3 to your computer and use it in GitHub Desktop.
Save wilcorrea/bfe1e478e8fd497f3417519a1067eeb3 to your computer and use it in GitHub Desktop.
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