Skip to content

Instantly share code, notes, and snippets.

@sagar-gavhane
Created January 12, 2019 12:26
Show Gist options
  • Save sagar-gavhane/080f93d585612b9abbe3771dfe66f357 to your computer and use it in GitHub Desktop.
Save sagar-gavhane/080f93d585612b9abbe3771dfe66f357 to your computer and use it in GitHub Desktop.
Yupjs multipleOfHundred custom validation
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