diff --git a/lib/helper.js b/lib/helper.js index 934a1f0..c6552ca 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -20,8 +20,12 @@ module.exports = function(options, key, validations, param) { else if (_.isFunction(validations)) { try { const test = validations(param); - if (!_.isBoolean(test)) { - return { error: 'The validation response must be boolean.' }; + // If the custom test returns a string, use that as the error message + if (_.isString(test)) { + return { error: test }; + } + else if (!_.isBoolean(test)) { + return { error: 'The validation response must be boolean or an error message.' }; } return test ? { value: param } : { error: 'The validation failed' }; } catch (e) {