import * as yup from 'yup' /* Add all react hook form rules with yup here. I left some examples, but you can edit and create your own. */ const registerSchema = yup.object().shape({ cpf: yup .string() .matches(/^\d{3}\.\d{3}\.\d{3}\-\d{2}$/, 'Deve informar um CPF válido') .required('Obrigatório informar um CPF'), firstname: yup .string() .min(2, 'Deve informar um nome válido') .required('Obrigatório informar o nome'), lastname: yup .string() .min(2, 'Deve conter no mínimo 6 caracteres') .required('Obrigatório informar um sobrenome'), email: yup .string() .matches( /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, 'Deve informar um e-mail válido', ) .required('Obrigatório informar um e-mail'), phone: yup .string() .matches( /^(?:(?:\+|00)?(55)\s?)?(?:\(?([1-9][0-9])\)?\s?)?(?:((?:9\d|[2-9])\d{3})\-?(\d{4}))$/, 'Deve informar um telefone válido', ) .required('Obrigatório informar um telefone'), birthdate: yup .string() .matches( /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/, 'O formato deve ser DD/MM/AAAA', ) .required('Obrigatório informar a data de nascimento'), healthcare: yup .bool() .required('Obrigatório informar se trabalha na área da saúde'), occupation: yup.string().when('healthcare', { is: true, then: yup.string().required('Obrigatório informar o cargo'), }), councilType: yup.string().when('healthcare', { is: true, then: yup.string().required('Obrigatório informar o tipo do conselho'), }), exemption: yup.bool(), councilNumber: yup.string().when('healthcare', { is: true, then: yup.string().when('exemption', { is: false, then: yup.string().required('Obrigatório informar o número do conselho'), }), }), }) const createPasswordSchema = yup.object().shape({ password: yup .string() .required('Obrigatório informar a senha') .min(8, 'Ter pelo menos 8 caracteres') .matches( /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/, 'Ter pelo menos 1 caractere especial', ) .matches(/[A-Z]/, 'Ter pelo menos 1 letra maiúscula') .matches(/[a-z]/, 'Ter pelo menos 1 letra minúscula') .matches(/\d/, 'Ter pelo menos 1 número'), passwordConfirm: yup .string() .oneOf([yup.ref('password'), null], 'Senhas não conferem') .required('Obrigatório informar a confirmação de senha'), checkTerms: yup .bool() .oneOf([true], 'Obrigatório aceitar os termos') .required('Obrigatório aceitar os termos'), }) const loginSchema = yup.object().shape({ cpf: yup .string() .matches(/^\d{3}\.\d{3}\.\d{3}\-\d{2}$/, 'Deve informar um CPF válido') .required('Obrigatório informar um CPF'), password: yup.string().required('Obrigatório informar a senha'), }) export { registerSchema, createPasswordSchema, loginSchema }