ÿØÿà JFIF ` ` ÿþ
|
Server : Apache System : Linux cloud.heroica.com.br 4.18.0-553.36.1.el8_10.x86_64 #1 SMP Wed Jan 22 03:07:54 EST 2025 x86_64 User : farolpborg ( 1053) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /var/www/node_services/apicentralquestoes/src/validations/ |
Upload File : |
const MENSAGENS_ERRO = require("../utils/mensagensErro");
const validarEntradaUsuario = (
nome,
email,
senha,
telefone,
faculdade,
cpf
) => {
if (!nome || !email || !senha || !telefone || !faculdade || !cpf)
if (!nome || !email || !senha || !telefone || !faculdade || !cpf)
return { erro: 400, mensagem: MENSAGENS_ERRO.CAMPOS_OBRIGATORIOS };
if (!nome || nome.length < 3)
return { erro: 400, mensagem: MENSAGENS_ERRO.NOME_CURTO };
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!emailRegex.test(email.trim()))
return { erro: 400, mensagem: MENSAGENS_ERRO.EMAIL_INVALIDO };
const senhaRegex =
/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[$*&@#])[A-Za-z\d$*&@#]{8,}$/;
if (!senhaRegex.test(senha))
return { erro: 400, mensagem: MENSAGENS_ERRO.SENHA_INVALIDA };
const telefoneRegex = /^\(\d{2}\) \d{4,5}-\d{4}$/;
if (!telefoneRegex.test(telefone))
return { erro: 400, mensagem: MENSAGENS_ERRO.TELEFONE_INVALIDO };
return null;
};
const validarCPF = (cpf) => {
cpf = cpf.replace(/[^\d]+/g, "");
if (cpf.length !== 11 || /^(\d)\1+$/.test(cpf)) return false;
let soma = 0;
for (let i = 0; i < 9; i++) soma += parseInt(cpf.charAt(i)) * (10 - i);
let resto = (soma * 10) % 11;
if (resto === 10 || resto === 11) resto = 0;
if (resto !== parseInt(cpf.charAt(9))) return false;
soma = 0;
for (let i = 0; i < 10; i++) soma += parseInt(cpf.charAt(i)) * (11 - i);
resto = (soma * 10) % 11;
if (resto === 10 || resto === 11) resto = 0;
return resto === parseInt(cpf.charAt(10));
};
module.exports = {
validarEntradaUsuario,
validarCPF,
};