Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 1x 40x 38x 19x 40x 38x 19x | import * as Yup from "yup";
import { FIELD_REQUIRED_MESSAGE } from "@sections/PayBuilder/Checkout/consts";
import {
isNonValidExpirationDate,
isValidCardNumber,
} from "@sections/PayBuilder/Checkout/helpers";
import { NAME_REGEX } from "@validation/regex";
import { VALIDATION_MESSAGES } from "@validation/messages";
export const formSchema = Yup.object().shape({
payment: Yup.object().shape({
cardNumber: Yup.string()
.required(FIELD_REQUIRED_MESSAGE)
.when({
is: (exists: string) => !!exists,
then: (schema) =>
schema.test(
"is-valid-card-number",
"Please enter a valid card number",
function (value) {
return isValidCardNumber(value || "");
},
),
}),
expirationDate: Yup.string()
.required(FIELD_REQUIRED_MESSAGE)
.when({
is: (exists: string) => !!exists,
then: (schema) =>
schema
.min(5, "Please enter a valid expiration date")
.test(
"validator-expiration-date",
"Please enter a valid expiration date",
function (value) {
return !isNonValidExpirationDate(value || "");
},
),
}),
cvv: Yup.string()
.required(FIELD_REQUIRED_MESSAGE)
.min(3, "Please enter a valid CVV"),
nameOnCard: Yup.string()
.trim()
.required(FIELD_REQUIRED_MESSAGE)
.matches(NAME_REGEX, VALIDATION_MESSAGES.INVALID_NAME_ENTER),
}),
});
|