diff --git a/src/components/FormInput/FormInput.tsx b/src/components/FormInput/FormInput.tsx index 7d7739f..f2aa14d 100644 --- a/src/components/FormInput/FormInput.tsx +++ b/src/components/FormInput/FormInput.tsx @@ -15,9 +15,9 @@ interface IFormikValues { nome: string; email: string; cpf: string; - //nascimento: string; - //tel: string; - //instagram: string; + nascimento: string; + tel: string; + instagram: string; termos: boolean; } const FormInput = () => { @@ -25,9 +25,9 @@ const FormInput = () => { nome: "", email: "", cpf: "", - //nascimento: "", - //tel: "", - //instagram: "", + nascimento: "", + tel: "", + instagram: "", termos: false, }; /* const formik = useFormik({ @@ -90,6 +90,39 @@ const FormInput = () => { return regex.test(value); } }), + nascimento: Yup.string() + .required("*Campo Obrigatório") + .test( + "nascimento", + "Preencha com uma data válida.", + function (value: any) { + if (value === "" || value === undefined) { + return false; + } else { + const nascimentoRegex = + "^(0[1-9]|[12][0-9]|3[01]).(0[1-9]|1[012]).[12][0-9]{3}$"; + const regex = new RegExp(nascimentoRegex); + return regex.test(value); + } + } + ), + tel: Yup.string() + .required("*Campo Obrigatório") + .test( + "telefone", + "Preencha com um telefone válido.", + function (value: any) { + if (value === "" || value === undefined) { + return false; + } else { + const telefoneRegex = + "^((\\+\\d{2}\\s)?\\(\\d{2}\\)\\s?\\d{4}\\d?\\-\\d{4})?$"; + const regex = new RegExp(telefoneRegex); + return regex.test(value); + } + } + ), + instagram: Yup.string(), termos: Yup.boolean().oneOf([true], "*"), }); const handleFormikSubmit = (values: IFormikValues) => { @@ -160,6 +193,60 @@ const FormInput = () => { className={errors.cpf && touched.cpf && "invalid"} /> +