diff --git a/src/components/schema/CustonValidationsRegex.ts b/src/components/schema/CustonValidationsRegex.ts new file mode 100644 index 0000000..e9f8791 --- /dev/null +++ b/src/components/schema/CustonValidationsRegex.ts @@ -0,0 +1,9 @@ +export const phoneNumber = + /^\(?[1-9]{2}\)? ?(?:[2-8]|9[1-9])[0-9]{3}\-?[0-9]{4}$/; + +// export const cpfNumber = /\d{3}.\d{3}.\d{3}-\d{2}/; +export const cpfNumber = + /^([0-9]{3}\.?[0-9]{3}\.?[0-9]{3}\-?[0-9]{2}|[0-9]{2}\.?[0-9]{3}\.?[0-9]{3}\/?[0-9]{4}\-?[0-9]{2})$/; + +export const insta = + /(?:^|[^\w])(?:@)([\w-](?:(?:[\w-]|(?:\.(?!\.))){0,28}(?:[\w-]))?)/; diff --git a/src/components/schema/FormSchema.ts b/src/components/schema/FormSchema.ts new file mode 100644 index 0000000..831a175 --- /dev/null +++ b/src/components/schema/FormSchema.ts @@ -0,0 +1,20 @@ +import * as Yup from "yup"; + +import { phoneNumber, cpfNumber, insta } from "./CustonValidationsRegex"; + +export default Yup.object().shape({ + name: Yup.string().required("*Campo Obrigatório"), + email: Yup.string() + .email() + .required("*Campo Obrigatório") + .email("E-mail inválido"), + cpf: Yup.string() + .matches(cpfNumber, "CPF inválido") + .required("*Campo Obrigatório"), + telefone: Yup.string() + .matches(phoneNumber, "numero inválido") + .required("*Campo Obrigatório"), + instagram: Yup.string().matches(insta, "conta inválida"), + data: Yup.date().required("*Campo Obrigatório"), + checkbox: Yup.boolean().oneOf([true], "*"), +});