-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator.js
More file actions
71 lines (55 loc) · 1.44 KB
/
Copy pathvalidator.js
File metadata and controls
71 lines (55 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const validator = {
// ...
isValid: (numdigitos) => {
// let arr = Array.from(numdigitos.value).reverse();
if(numdigitos === '') return false;
let temp = 0,
resta = 0,
suma = 0;
let arr = Array.from(numdigitos).map(i => parseInt(i)).reverse();
//console.log(arr);
for (let i = 0; i < arr.length; i++) {
//Si el numero es par se multiplica por dos
if ((i+1) % 2 === 0) {
temp = arr[i] * 2
//
if (temp >= 10) {
temp-=9
//console.log('resta', temp)
}
suma += temp;
// debugger
}
else {
suma += resta
suma+= arr[i]
//console.log(suma)
}
}
console.log(suma);
if (suma % 10 === 0) {
return true
}
else{
return false
}
},
maskify:(digitos) => {
//let coso= document.getElementById(digitos).value
//let mascara = document.getElementById("digitos")
//digitos = digitos.toString()
let acumulador = ""
for (let i = 0; i <digitos.length; i++) {
if (i > digitos.length -5) {
acumulador = acumulador + digitos[i]
}
else {
acumulador = acumulador + "#"
//
}
}
console.log(acumulador)
return acumulador
}
}
export default validator;