Created
August 25, 2020 20:12
-
-
Save marcelocmenezes/bddaa515fc2a9af4d466b829af0a8820 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Yup from 'yup'; | |
import { validateCpf } from '../../utils/validateCpf'; | |
import { validatePhone } from '../../utils/validatePhone'; | |
function isValidCPF(this: Yup.StringSchema) { | |
return this.test({ name: 'cpf', message: 'CPF Inválido', test: value => validateCpf(value) }); | |
} | |
function isValidPhoneNumber(this: Yup.StringSchema) { | |
return this.test({ name: 'sms', message: 'Número inválido', test: value => validatePhone(value) }); | |
} | |
Yup.addMethod<Yup.StringSchema>(Yup.string, 'isValidCPF', isValidCPF); | |
Yup.addMethod<Yup.StringSchema>(Yup.string, 'isValidPhoneNumber', isValidPhoneNumber); | |
declare module 'yup' { | |
interface StringSchema { | |
isValidCPF(): Yup.StringSchema; | |
isValidPhoneNumber(): Yup.StringSchema; | |
} | |
} | |
export default Yup; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment