1 回答

TA貢獻1963條經驗 獲得超6個贊
該test方法可以是其中之一。在方法內部,您可以使用test訪問其他字段(此處) 。只需制作一個像這樣的自定義驗證器:carriercodethis.parent['carriercode']
Yup.object({
carriercode: Yup.string().required(requiredMessage).min(4, "length should be 4").matches(/^[a-zA-Z0-9-]+$/, "Can not contain special characters like ),(,@ etc."),
blnum: Yup.string()
.required("Should be the prefix of carriercode") //validate if blnum starts with carriercode
.test("Check prefix", function () {
let carriercode = this.parent["carriercode"];
let blnum = this.parent["blnum"];
// console.log(carriercode, blnum);
if (carriercode && blnum) {
return blnum.startsWith(carriercode) ? true : false;
}
})
})
添加回答
舉報