Created
January 12, 2019 12:26
-
-
Save sagar-gavhane/080f93d585612b9abbe3771dfe66f357 to your computer and use it in GitHub Desktop.
Yupjs multipleOfHundred custom validation
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"; | |
const values = 0; | |
const msg = "value should be multiple of hundred"; | |
Yup.addMethod(Yup.number, "multipleOfHundred", function(msg) { | |
return this.test("test-name", msg, function(value) { | |
const { path, createError } = this; | |
return value % 100 === 0 && value !== 0; | |
}); | |
}); | |
const schema = Yup.number().multipleOfHundred(); | |
schema.isValid(values).then(res => console.log(res)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment