-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
78 lines (75 loc) · 2.41 KB
/
functions.js
File metadata and controls
78 lines (75 loc) · 2.41 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
72
73
74
75
76
77
78
const format = {
RG: function formatRG(rg){
rg = rg.toString().replace(/[^0-9]/g, '')
if(rg.length>10){
rg = rg.slice(0,10)
}
return rg
},
CNPJ: function formatCNPJ(cnpj) {
cnpj = cnpj.toString().replace(/[^0-9]/g, '')
if(cnpj.length>2){
cnpj = cnpj.slice(0,2) + '.' + cnpj.slice(2)
}
if(cnpj.length>6){
cnpj = cnpj.slice(0, 6)+'.'+cnpj.slice(6)
}
if(cnpj.length>10){
cnpj = cnpj.slice(0, 10) + '/' + cnpj.slice(10)
}
if(cnpj.length>15){
cnpj = cnpj.slice(0, 15) + '-' +cnpj.slice(15)
}
if(cnpj.length>18){
cnpj = cnpj.slice(0, 18)
}
return cnpj
},
CPF: function formatCPF(cpf) {
cpf = cpf.toString().replace(/[^0-9]/g, '')
if(cpf.length>3){
cpf = cpf.slice(0,3) + '.' + cpf.slice(3)
}
if(cpf.length>7){
cpf = cpf.slice(0,7)+'.' + cpf.slice(7)
}
if(cpf.length>11){
cpf = cpf.slice(0,11) + '-' +cpf.slice(11)
}
if(cpf.length>14){
cpf = cpf.slice(0, 14)
}
return cpf
},
Telefone: function formatFone(fone) {
fone = fone.toString().replace(/[^0-9]/g, '')
if(fone.length>0){
fone = '(' +fone
}
if(fone.length>3){
fone = fone.slice(0, 3) + ') ' + fone.slice(3)
}
if(fone.length>10){
fone = fone.slice(0, 10) + '-' + fone.slice(10)
}
if(fone.length>15){
fone = fone.slice(0, 15)
}
return fone
},
CEP: function formatCEP(cep) {
cep = cep.toString().replace(/[^0-9]/g, '')
if(cep.length>5){
cep = cep.slice(0, 5) + '-' + cep.slice(5)
}
if(cep.length>9){
cep = cep.slice(0, 9)
}
return cep
}
}
//format.CPF(cpf) formata o CPF
//format.RG(rg) formata o RG
//format.CNPJ(cnpj) formata o CNPJ
//format.Telefone(fone) formata o número de telefone (apenas código de área + 9 digitos)
//format.CEP(cep) formata o cep