forked from carlosspohr/jQuery-CPF-Validate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.cpf-validate.1.0.min.js
56 lines (53 loc) · 1.09 KB
/
jquery.cpf-validate.1.0.min.js
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
(function ( $ ) {
$.fn.validateCPF = function(a) {
var b = this;
var c = b.val().replace('.', '').replace('.', '').replace('-', '');
if (c.length != 11) {
return false;
} else {
var d = /1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}|0{11}/;
if (d.test(c)) {
return false;
} else {
var x = 0;
var y = 0;
var e = 0;
var f = 0;
var g = 0;
var h = "";
var k = "";
var l = c.length;
x = l - 1;
for ( var i = 0; i <= l - 3; i++) {
y = c.substring(i, i + 1);
e = e + (y * x);
x = x - 1;
h = h + y;
}
f = 11 - (e % 11);
if (f == 10 || f == 11) {
f = 0;
}
k = c.substring(0, l - 2) + f;
x = 11;
e = 0;
for ( var j = 0; j <= (l - 2); j++) {
e = e + (k.substring(j, j + 1) * x);
x = x - 1;
}
g = 11 - (e % 11);
if (g == 10) {
g = 0;
}
if (g == 11) {
g = 0;
}
if ((f + "" + g) == c.substring(l, l - 2)) {
return true;
} else {
return false;
}
}
}
};
}( jQuery ));