Last active
May 29, 2019 18:09
-
-
Save codeBelt/747a921d355bdea02fc16dd3049bfcb9 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
validationSchema: yup.object().shape({ | |
firstName: yup.string().required(validationMessages.firstName), | |
lastName: yup.string().required(validationMessages.lastName), | |
emailAddress: yup | |
.string() | |
.email(validationMessages.email) | |
.test('eitherOr', validationMessages.eitherEmail, function(emailAddress) { | |
// tslint:disable-next-line:no-invalid-this | |
return Boolean(emailAddress) || Boolean(this.parent.pin); | |
}), | |
pin: yup | |
.string() | |
.min(6, validationMessages.pinMaxMinDigits) | |
.max(6, validationMessages.pinMaxMinDigits) | |
.test('eitherOr', validationMessages.eitherPin, function(pin) { | |
// tslint:disable-next-line:no-invalid-this | |
return Boolean(pin) || Boolean(this.parent.emailAddress); | |
}), | |
roles: yup.array().of( | |
yup.object().shape({ | |
label: yup.string().required(), | |
value: yup.string().required(), | |
}) | |
), | |
}), |
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
Yup.match = function (key, message, func) { | |
message = message || 'Values do not match'; | |
func = func || function (value) { | |
return value === this.options.context[key]; | |
} | |
return Yup.mixed().test('match', message, func); | |
}; | |
var schema = { | |
email: Yup.string().email(), | |
confirmEmail: Yup.match('email', 'Emails do not match') | |
} |
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'; | |
validationSchema: Yup.object({ | |
password: Yup.string().required('Password is required'), | |
passwordConfirmation: Yup.string() | |
.oneOf([Yup.ref('password'), null], 'Passwords must match') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment