feat(institucional):validações do formulário concluidas

This commit is contained in:
Gustavo Rallenson Gonçalves Da Silva 2023-01-12 18:41:16 -03:00
parent 0d5b77da84
commit 8592244765
2 changed files with 14 additions and 3 deletions

View File

@ -33,6 +33,7 @@ const initialValues = {
}
const Home = () =>{
const [activeSection, setActiveSection] = useState("Sobre");
const [isChecked, setIsChecked] = useState(false);
@ -44,7 +45,14 @@ const Home = () =>{
console.log(values)
setIsChecked(false)
values.birthdate = moment(values.birthdate, 'DDMMYYYY').format('DD/MM/YYYY');
values.cpf = values.cpf.replace(/(\d{3})(\d)/, "$1.$2").replace(/(\d{3})(\d)/, "$1.$2").replace(/(\d{3})(\d{1,2})$/, "$1-$2")
values.cpf = values.cpf.replace(/(\d{3})(\d)/, "$1.$2")
.replace(/(\d{3})(\d)/, "$1.$2")
.replace(/(\d{3})(\d{1,2})$/, "$1-$2")
values.phone = values.phone.replace(/\D/g, '')
.replace(/(\d{2})(\d{5})(\d{4})/, "($1) $2-$3");
if (!values.instagram.startsWith("@")) {
values.instagram = `@${values.instagram}`;
}
formik.resetForm();
}

View File

@ -19,7 +19,6 @@ export default Yup.object().shape({
.required("* Campo Obrigatório")
.transform(value => isCPF.format(value))
.test("cpf-valid", "* CPF inválido", value => isCPF.validate(value))
,
birthdate: Yup.string()
@ -29,9 +28,13 @@ export default Yup.object().shape({
.transform(value => moment(value, "DD/MM/YYYY").format("DD/MM/YYYY")),
phone:Yup.string()
.matches(/^\(?\d{2}\)?[\s-]?\d{5}-?\d{4}$/, 'Invalid phone number format.')
.required("* Campo Obrigatório"),
instagram:Yup.string(),
instagram:Yup.string()
.matches(/^@?[a-zA-Z0-9_]+$/, "* Formato de usuário inválido")
.max(30, "* O nome de usuário não pode ter mais de 30 caracteres"),
aceito: Yup.boolean()
.required()