PageSourceSearch

https://cultura.rj.gov.br/wp-content/themes/secec/js/validador.js

js cultura.rj.gov.br collected 2026-10-02 07:33:11 UTC 3,023 bytes, 126 lines download raw bytes

1window.onload = () => {
2  let inputs = document.querySelectorAll("#formcontato > *:not(button)");
3
4  inputs.forEach(input => {
5    input.addEventListener("blur", () => {
6      if (input.value.length > 0) {
7        if (!input.checkValidity()) {
8          input.style.border = "1px solid red";
9        }
10        else {
11          input.style.border = "none";
12          input.style.borderBottom = "1px solid var(--cor-terciaria)";
13        }
14      }
15      else {
16        input.style.borderBottom = "1px solid var(--cor-terciaria)";
17      }
18    });
19  });
20};
21
22function maskTel(inputField) {
23  let mask1 = "(99) 9999-9999";
24  let mask2 = "(99) 99999-9999";
25
26  inputField.addEventListener("input", () => {
27    if (inputField.value.replace(/\(/g, "").replace(/\)/g, "").replace(/\-/g, "").replace(/\s/g, "").length <= 10) {
28      VMasker(inputField).maskPattern(mask1);
29    }
30    else {
31      VMasker(inputField).maskPattern(mask2);
32    }
33  });
34}
35
36function maskCpf(inputField) {
37  VMasker(inputField).maskPattern("999.999.999-99");
38}
39
40function checkCpf(inputField) {
41  if (inputField.value.length > 0) {
42    if (!validateCpf(inputField.value)) {
43      invalidate(inputField, "CPF inválido");
44    }
45    else {
46      validate(inputField);
47    }
48  }
49  else {
50    inputField.style.borderBottom = "1px solid var(--cor-terciaria)";
51  }
52}
53
54function checkEmail(inputField) {
55  inputField.addEventListener("blur", () => {
56    if (inputField.value.length > 0) {
57      if (!inputField.value.match(/\w{1,}\@.{1,}/g)) {
58        invalidate(inputField, "Endereço de email inválido.");
59      }
60      else {
61        validate(inputField);
62      }
63    }
64    else {
65      inputField.style.borderBottom = "1px solid var(--cor-terciaria)";
66    }
67  });
68}
69
70function validateCpf(cpf) {
71  cpf = cpf.replace(/[^\d]+/g, '');
72
73  if (cpf == '') return false;
74
75	// Elimina CPFs invalidos conhecidos
76	if (cpf.length != 11 ||
77		cpf == "00000000000" ||
78		cpf == "11111111111" ||
79		cpf == "22222222222" ||
80		cpf == "33333333333" ||
81		cpf == "44444444444" ||
82		cpf == "55555555555" ||
83		cpf == "66666666666" ||
84		cpf == "77777777777" ||
85		cpf == "88888888888" ||
86		cpf == "99999999999")
87      return false;
88
89	// Valida 1o digito
90	add = 0;
91	for (i=0; i < 9; i ++)
92    add += parseInt(cpf.charAt(i)) * (10 - i);
93
94    rev = 11 - (add % 11);
95
96		if (rev == 10 || rev == 11)
97      rev = 0;
98
99		if (rev != parseInt(cpf.charAt(9)))
100      return false;
101
102	// Valida 2o digito
103	add = 0;
104	for (i = 0; i < 10; i ++)
105    add += parseInt(cpf.charAt(i)) * (11 - i);
106
107  rev = 11 - (add % 11);
108
109	if (rev == 10 || rev == 11)
110    rev = 0;
111
112	if (rev != parseInt(cpf.charAt(10)))
113		return false;
114	return true;
115}
116
117function validate(el) {
118  el.style.border = "none";
119  el.style.borderBottom = "1px solid var(--cor-terciaria)";
120  el.setCustomValidity('');
121}
122
123function invalidate(el, message) {
124  el.style.border = "1px solid red";
125  el.setCustomValidity(message);
126}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.