-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.html
More file actions
648 lines (591 loc) · 28.8 KB
/
Copy pathdemo.html
File metadata and controls
648 lines (591 loc) · 28.8 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ValidBR - Demo</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: Arial, sans-serif; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; padding: 20px; }
.container { max-width: 1200px; margin: 0 auto; background: white; border-radius: 20px; box-shadow: 0 20px 40px rgba(0,0,0,0.1); }
.header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 40px; text-align: center; }
.header h1 { font-size: 3rem; margin-bottom: 10px; }
.content { padding: 40px; }
.section { margin-bottom: 30px; padding: 20px; border: 1px solid #e1e5e9; border-radius: 10px; background: #fafbfc; }
.section h2 { color: #2c3e50; margin-bottom: 20px; border-bottom: 3px solid #667eea; padding-bottom: 10px; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 600; }
.form-group input, .form-group select { width: 100%; padding: 10px; border: 2px solid #e1e5e9; border-radius: 5px; }
.btn { background: #667eea; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; margin-right: 10px; }
.btn:hover { background: #5a6fd8; }
.result { margin-top: 10px; padding: 10px; border-radius: 5px; font-weight: 600; }
.result.success { background: #d4edda; color: #155724; }
.result.error { background: #f8d7da; color: #721c24; }
.result.info { background: #d1ecf1; color: #0c5460; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.footer { background: #2c3e50; color: white; text-align: center; padding: 20px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>ValidBR</h1>
<p>Biblioteca de Validação Brasileira - Demo Interativo</p>
</div>
<div class="content">
<!-- CPF -->
<div class="section">
<h2>🔍 Validação de CPF</h2>
<div class="grid">
<div>
<div class="form-group">
<label>CPF:</label>
<input type="text" id="cpfInput" placeholder="000.000.000-00" maxlength="14">
</div>
<button class="btn" onclick="validateCPF()">Validar CPF</button>
<button class="btn" onclick="generateCPF()">Gerar CPF</button>
<div id="cpfResult"></div>
</div>
<div>
<div class="form-group">
<label>CPF para identificar estado:</label>
<input type="text" id="cpfStateInput" placeholder="00000000000" maxlength="11">
</div>
<button class="btn" onclick="getCPFState()">Identificar Estado</button>
<div id="cpfStateResult"></div>
</div>
</div>
</div>
<!-- CNPJ -->
<div class="section">
<h2>🏢 Validação de CNPJ</h2>
<div class="grid">
<div>
<div class="form-group">
<label>CNPJ:</label>
<input type="text" id="cnpjInput" placeholder="00.000.000/0000-00" maxlength="18">
</div>
<button class="btn" onclick="validateCNPJ()">Validar CNPJ</button>
<button class="btn" onclick="generateCNPJ()">Gerar CNPJ</button>
<div id="cnpjResult"></div>
</div>
</div>
</div>
<!-- Telefone -->
<div class="section">
<h2>📞 Validação de Telefone</h2>
<div class="grid">
<div>
<div class="form-group">
<label>Telefone:</label>
<input type="text" id="phoneInput" placeholder="(11) 91234-5678" maxlength="15">
</div>
<button class="btn" onclick="validatePhone()">Validar Telefone</button>
<button class="btn" onclick="getDDDInfo()">Info DDD</button>
<div id="phoneResult"></div>
</div>
<div>
<div class="form-group">
<label>DDD:</label>
<input type="text" id="dddInput" placeholder="11" maxlength="2">
</div>
<button class="btn" onclick="getDDDState()">Estado do DDD</button>
<div id="dddResult"></div>
</div>
</div>
</div>
<!-- Email -->
<div class="section">
<h2>✉️ Validação de Email</h2>
<div class="form-group">
<label>Email:</label>
<input type="email" id="emailInput" placeholder="usuario@exemplo.com">
</div>
<button class="btn" onclick="validateEmail()">Validar Email</button>
<button class="btn" onclick="sanitizeEmail()">Sanitizar</button>
<div id="emailResult"></div>
</div>
<!-- Nome -->
<div class="section">
<h2>👤 Validação de Nome</h2>
<div class="grid">
<div>
<div class="form-group">
<label>Nome Completo:</label>
<input type="text" id="nameInput" placeholder="João Silva Santos">
</div>
<button class="btn" onclick="validateName()">Validar Nome</button>
<button class="btn" onclick="getInitials()">Obter Iniciais</button>
<div id="nameResult"></div>
</div>
</div>
</div>
<!-- Data de Nascimento -->
<div class="section">
<h2>📅 Validação de Data de Nascimento</h2>
<div class="grid">
<div>
<div class="form-group">
<label>Data de Nascimento:</label>
<input type="date" id="birthDateInput">
</div>
<button class="btn" onclick="validateBirthDate()">Validar Data</button>
<button class="btn" onclick="calculateAge()">Calcular Idade</button>
<div id="birthDateResult"></div>
</div>
</div>
</div>
<!-- CEP -->
<div class="section">
<h2>📮 Validação de CEP</h2>
<div class="grid">
<div>
<div class="form-group">
<label>CEP:</label>
<input type="text" id="cepInput" placeholder="00000-000" maxlength="9">
</div>
<button class="btn" onclick="validateCEP()">Validar CEP</button>
<button class="btn" onclick="getCEPInfo()">Buscar Endereço</button>
<div id="cepResult"></div>
</div>
</div>
</div>
<!-- Utilitários -->
<div class="section">
<h2>🛠️ Funções Utilitárias</h2>
<div class="grid">
<div>
<div class="form-group">
<label>Texto para sanitizar:</label>
<input type="text" id="sanitizeInput" placeholder=" texto@exemplo.com ">
</div>
<button class="btn" onclick="sanitizeText()">Sanitizar</button>
<div id="sanitizeResult"></div>
</div>
<div>
<div class="form-group">
<label>Texto para processar:</label>
<input type="text" id="removeInput" placeholder="abc123def456">
</div>
<button class="btn" onclick="removeNonNumeric()">Remover Não-Numéricos</button>
<button class="btn" onclick="removeNonAlphabetic()">Remover Não-Alfabéticos</button>
<div id="removeResult"></div>
</div>
</div>
</div>
<!-- CNH -->
<div class="section">
<h2>🚗 Validação de CNH</h2>
<div class="grid">
<div>
<div class="form-group">
<label>CNH:</label>
<input type="text" id="cnhInput" placeholder="00000000000" maxlength="11">
</div>
<button class="btn" onclick="validateCNH()">Validar CNH</button>
<button class="btn" onclick="generateCNH()">Gerar CNH</button>
<div id="cnhResult"></div>
</div>
</div>
</div>
<!-- Título de Eleitor -->
<div class="section">
<h2>🗳️ Validação de Título de Eleitor</h2>
<div class="grid">
<div>
<div class="form-group">
<label>Título de Eleitor:</label>
<input type="text" id="tituloInput" placeholder="0000 0000 0000" maxlength="14">
</div>
<button class="btn" onclick="validateTitulo()">Validar Título</button>
<button class="btn" onclick="generateTitulo()">Gerar Título</button>
<div id="tituloResult"></div>
</div>
</div>
</div>
<!-- PIS -->
<div class="section">
<h2>💼 Validação de PIS</h2>
<div class="grid">
<div>
<div class="form-group">
<label>PIS:</label>
<input type="text" id="pisInput" placeholder="000.00000.00-0" maxlength="14">
</div>
<button class="btn" onclick="validatePIS()">Validar PIS</button>
<button class="btn" onclick="generatePIS()">Gerar PIS</button>
<div id="pisResult"></div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>ValidBR - Biblioteca de Validação Brasileira</p>
<p>Desenvolvido com ❤️ para a comunidade brasileira</p>
</div>
</div>
<script>
// Simulação das funções do ValidBR
class ValidBR {
static cpf = {
isValid: (cpf) => {
const clean = cpf.replace(/\D/g, '');
if (clean.length !== 11) return false;
if (/^(\d)\1{10}$/.test(clean)) return false;
let sum = 0;
for (let i = 0; i < 9; i++) {
sum += parseInt(clean[i]) * (10 - i);
}
let digit = 11 - (sum % 11);
if (digit > 9) digit = 0;
if (digit !== parseInt(clean[9])) return false;
sum = 0;
for (let i = 0; i < 10; i++) {
sum += parseInt(clean[i]) * (11 - i);
}
digit = 11 - (sum % 11);
if (digit > 9) digit = 0;
if (digit !== parseInt(clean[10])) return false;
return true;
},
generate: () => {
const digits = [];
for (let i = 0; i < 9; i++) {
digits.push(Math.floor(Math.random() * 10));
}
let sum = 0;
for (let i = 0; i < 9; i++) {
sum += digits[i] * (10 - i);
}
let digit = 11 - (sum % 11);
if (digit > 9) digit = 0;
digits.push(digit);
sum = 0;
for (let i = 0; i < 10; i++) {
sum += digits[i] * (11 - i);
}
digit = 11 - (sum % 11);
if (digit > 9) digit = 0;
digits.push(digit);
return digits.join('').replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, '$1.$2.$3-$4');
},
getState: (cpf) => {
const firstDigit = parseInt(cpf[0]);
const states = {
0: 'Rio Grande do Sul',
1: 'Distrito Federal, Goiás, Mato Grosso, Mato Grosso do Sul, Tocantins',
2: 'Amazonas, Pará, Roraima, Amapá, Acre, Rondônia',
3: 'Ceará, Maranhão, Piauí',
4: 'Paraíba, Pernambuco, Alagoas, Rio Grande do Norte',
5: 'Bahia, Sergipe',
6: 'Minas Gerais',
7: 'Rio de Janeiro, Espírito Santo',
8: 'São Paulo',
9: 'Paraná, Santa Catarina'
};
return states[firstDigit] || 'Estado não identificado';
}
};
static cnpj = {
isValid: (cnpj) => {
const clean = cnpj.replace(/\D/g, '');
if (clean.length !== 14) return false;
if (/^(\d)\1{13}$/.test(clean)) return false;
let sum = 0;
const weights = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
for (let i = 0; i < 12; i++) {
sum += parseInt(clean[i]) * weights[i];
}
let digit = 11 - (sum % 11);
if (digit > 9) digit = 0;
if (digit !== parseInt(clean[12])) return false;
sum = 0;
const weights2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
for (let i = 0; i < 13; i++) {
sum += parseInt(clean[i]) * weights2[i];
}
digit = 11 - (sum % 11);
if (digit > 9) digit = 0;
if (digit !== parseInt(clean[13])) return false;
return true;
},
generate: () => {
const digits = [];
for (let i = 0; i < 12; i++) {
digits.push(Math.floor(Math.random() * 10));
}
let sum = 0;
const weights = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
for (let i = 0; i < 12; i++) {
sum += digits[i] * weights[i];
}
let digit = 11 - (sum % 11);
if (digit > 9) digit = 0;
digits.push(digit);
sum = 0;
const weights2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
for (let i = 0; i < 13; i++) {
sum += digits[i] * weights2[i];
}
digit = 11 - (sum % 11);
if (digit > 9) digit = 0;
digits.push(digit);
return digits.join('').replace(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, '$1.$2.$3/$4-$5');
}
};
static phone = {
isValid: (phone) => {
const clean = phone.replace(/\D/g, '');
return clean.length >= 10 && clean.length <= 11;
},
getState: (ddd) => {
const dddStates = {
'11': 'São Paulo', '12': 'São Paulo', '13': 'São Paulo', '14': 'São Paulo',
'15': 'São Paulo', '16': 'São Paulo', '17': 'São Paulo', '18': 'São Paulo',
'19': 'São Paulo', '21': 'Rio de Janeiro', '22': 'Rio de Janeiro',
'24': 'Rio de Janeiro', '27': 'Espírito Santo', '28': 'Espírito Santo',
'31': 'Minas Gerais', '32': 'Minas Gerais', '33': 'Minas Gerais',
'34': 'Minas Gerais', '35': 'Minas Gerais', '37': 'Minas Gerais',
'38': 'Minas Gerais', '41': 'Paraná', '42': 'Paraná', '43': 'Paraná',
'44': 'Paraná', '45': 'Paraná', '46': 'Paraná', '47': 'Santa Catarina',
'48': 'Santa Catarina', '49': 'Santa Catarina', '51': 'Rio Grande do Sul',
'53': 'Rio Grande do Sul', '54': 'Rio Grande do Sul', '55': 'Rio Grande do Sul'
};
return dddStates[ddd] || 'Estado não encontrado';
}
};
static email = {
isValid: (email) => {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
},
sanitize: (email) => {
return email.trim().toLowerCase();
}
};
static name = {
isValid: (name) => {
return name.trim().length >= 2 && /^[a-zA-ZÀ-ÿ\s]+$/.test(name);
},
getInitials: (name) => {
return name.split(' ').map(word => word.charAt(0).toUpperCase()).join('');
}
};
static birthDate = {
isValid: (date) => {
const birthDate = new Date(date);
const today = new Date();
const age = today.getFullYear() - birthDate.getFullYear();
return age >= 0 && age <= 130;
},
getAge: (date) => {
const birthDate = new Date(date);
const today = new Date();
let age = today.getFullYear() - birthDate.getFullYear();
const monthDiff = today.getMonth() - birthDate.getMonth();
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
return age;
}
};
static cep = {
isValid: (cep) => {
const clean = cep.replace(/\D/g, '');
return clean.length === 8;
}
};
static sanitize = (text) => {
return text.trim();
};
static removeNonNumeric = (text) => {
return text.replace(/\D/g, '');
};
static removeNonAlphabetic = (text) => {
return text.replace(/[^a-zA-ZÀ-ÿ\s]/g, '');
};
}
// Funções de interface
function showResult(elementId, message, type = 'info') {
const element = document.getElementById(elementId);
element.innerHTML = `<div class="result ${type}">${message}</div>`;
}
function validateCPF() {
const cpf = document.getElementById('cpfInput').value;
const isValid = ValidBR.cpf.isValid(cpf);
const message = isValid ? `✅ CPF válido: ${cpf}` : '❌ CPF inválido';
showResult('cpfResult', message, isValid ? 'success' : 'error');
}
function generateCPF() {
const cpf = ValidBR.cpf.generate();
document.getElementById('cpfInput').value = cpf;
showResult('cpfResult', `✅ CPF gerado: ${cpf}`, 'success');
}
function getCPFState() {
const cpf = document.getElementById('cpfStateInput').value.replace(/\D/g, '');
if (cpf.length === 11) {
const state = ValidBR.cpf.getState(cpf);
showResult('cpfStateResult', `📍 Estado: ${state}`, 'info');
} else {
showResult('cpfStateResult', '❌ CPF deve ter 11 dígitos', 'error');
}
}
function validateCNPJ() {
const cnpj = document.getElementById('cnpjInput').value;
const isValid = ValidBR.cnpj.isValid(cnpj);
const message = isValid ? `✅ CNPJ válido: ${cnpj}` : '❌ CNPJ inválido';
showResult('cnpjResult', message, isValid ? 'success' : 'error');
}
function generateCNPJ() {
const cnpj = ValidBR.cnpj.generate();
document.getElementById('cnpjInput').value = cnpj;
showResult('cnpjResult', `✅ CNPJ gerado: ${cnpj}`, 'success');
}
function validatePhone() {
const phone = document.getElementById('phoneInput').value;
const isValid = ValidBR.phone.isValid(phone);
const message = isValid ? `✅ Telefone válido: ${phone}` : '❌ Telefone inválido';
showResult('phoneResult', message, isValid ? 'success' : 'error');
}
function getDDDInfo() {
const phone = document.getElementById('phoneInput').value;
const ddd = phone.replace(/\D/g, '').substring(0, 2);
const state = ValidBR.phone.getState(ddd);
showResult('phoneResult', `📍 DDD ${ddd}: ${state}`, 'info');
}
function getDDDState() {
const ddd = document.getElementById('dddInput').value;
const state = ValidBR.phone.getState(ddd);
showResult('dddResult', `📍 Estado do DDD ${ddd}: ${state}`, 'info');
}
function validateEmail() {
const email = document.getElementById('emailInput').value;
const isValid = ValidBR.email.isValid(email);
const message = isValid ? `✅ Email válido: ${email}` : '❌ Email inválido';
showResult('emailResult', message, isValid ? 'success' : 'error');
}
function sanitizeEmail() {
const email = document.getElementById('emailInput').value;
const sanitized = ValidBR.email.sanitize(email);
document.getElementById('emailInput').value = sanitized;
showResult('emailResult', `🧹 Email sanitizado: ${sanitized}`, 'info');
}
function validateName() {
const name = document.getElementById('nameInput').value;
const isValid = ValidBR.name.isValid(name);
const message = isValid ? `✅ Nome válido: ${name}` : '❌ Nome inválido';
showResult('nameResult', message, isValid ? 'success' : 'error');
}
function getInitials() {
const name = document.getElementById('nameInput').value;
const initials = ValidBR.name.getInitials(name);
showResult('nameResult', `🔤 Iniciais: ${initials}`, 'info');
}
function validateBirthDate() {
const date = document.getElementById('birthDateInput').value;
const isValid = ValidBR.birthDate.isValid(date);
const message = isValid ? `✅ Data válida: ${date}` : '❌ Data inválida';
showResult('birthDateResult', message, isValid ? 'success' : 'error');
}
function calculateAge() {
const date = document.getElementById('birthDateInput').value;
const age = ValidBR.birthDate.getAge(date);
showResult('birthDateResult', `🎂 Idade: ${age} anos`, 'info');
}
function validateCEP() {
const cep = document.getElementById('cepInput').value;
const isValid = ValidBR.cep.isValid(cep);
const message = isValid ? `✅ CEP válido: ${cep}` : '❌ CEP inválido';
showResult('cepResult', message, isValid ? 'success' : 'error');
}
function getCEPInfo() {
const cep = document.getElementById('cepInput').value;
showResult('cepResult', '🔍 Buscando informações do CEP... (simulação)', 'info');
}
function sanitizeText() {
const text = document.getElementById('sanitizeInput').value;
const sanitized = ValidBR.sanitize(text);
showResult('sanitizeResult', `🧹 Texto sanitizado: "${sanitized}"`, 'info');
}
function removeNonNumeric() {
const text = document.getElementById('removeInput').value;
const result = ValidBR.removeNonNumeric(text);
showResult('removeResult', `🔢 Apenas números: "${result}"`, 'info');
}
function removeNonAlphabetic() {
const text = document.getElementById('removeInput').value;
const result = ValidBR.removeNonAlphabetic(text);
showResult('removeResult', `🔤 Apenas letras: "${result}"`, 'info');
}
// CNH
function validateCNH() {
const cnh = document.getElementById('cnhInput').value;
const isValid = ValidBR.cnh.isValid(cnh);
const message = isValid ? `✅ CNH válida: ${cnh}` : '❌ CNH inválida';
showResult('cnhResult', message, isValid ? 'success' : 'error');
}
function generateCNH() {
const cnh = ValidBR.cnh.generate();
document.getElementById('cnhInput').value = cnh;
showResult('cnhResult', `✅ CNH gerada: ${cnh}`, 'success');
}
// Título de Eleitor
function validateTitulo() {
const titulo = document.getElementById('tituloInput').value;
const isValid = ValidBR.tituloEleitor.isValid(titulo);
const message = isValid ? `✅ Título válido: ${titulo}` : '❌ Título inválido';
showResult('tituloResult', message, isValid ? 'success' : 'error');
}
function generateTitulo() {
const titulo = ValidBR.tituloEleitor.generate();
document.getElementById('tituloInput').value = titulo;
showResult('tituloResult', `✅ Título gerado: ${titulo}`, 'success');
}
// PIS
function validatePIS() {
const pis = document.getElementById('pisInput').value;
const isValid = ValidBR.pis.isValid(pis);
const message = isValid ? `✅ PIS válido: ${pis}` : '❌ PIS inválido';
showResult('pisResult', message, isValid ? 'success' : 'error');
}
function generatePIS() {
const pis = ValidBR.pis.generate();
document.getElementById('pisInput').value = pis;
showResult('pisResult', `✅ PIS gerado: ${pis}`, 'success');
}
// Máscaras automáticas
document.getElementById('cpfInput').addEventListener('input', function(e) {
let value = e.target.value.replace(/\D/g, '');
if (value.length <= 11) {
value = value.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, '$1.$2.$3-$4');
e.target.value = value;
}
});
document.getElementById('cnpjInput').addEventListener('input', function(e) {
let value = e.target.value.replace(/\D/g, '');
if (value.length <= 14) {
value = value.replace(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, '$1.$2.$3/$4-$5');
e.target.value = value;
}
});
document.getElementById('phoneInput').addEventListener('input', function(e) {
let value = e.target.value.replace(/\D/g, '');
if (value.length <= 11) {
if (value.length === 11) {
value = value.replace(/(\d{2})(\d{5})(\d{4})/, '($1) $2-$3');
} else if (value.length === 10) {
value = value.replace(/(\d{2})(\d{4})(\d{4})/, '($1) $2-$3');
}
e.target.value = value;
}
});
document.getElementById('cepInput').addEventListener('input', function(e) {
let value = e.target.value.replace(/\D/g, '');
if (value.length <= 8) {
value = value.replace(/(\d{5})(\d{3})/, '$1-$2');
e.target.value = value;
}
});
</script>
</body>
</html>