From 2b26ab85c73d86e433365015da30b298c5938e75 Mon Sep 17 00:00:00 2001 From: 1on Date: Mon, 25 May 2020 13:42:40 +0300 Subject: [PATCH] email, startsWith and endsWith validators now return valid result if value is empty --- src/libs/rules.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libs/rules.js b/src/libs/rules.js index 13d1914..788ea35 100644 --- a/src/libs/rules.js +++ b/src/libs/rules.js @@ -109,6 +109,10 @@ export default { * Rule: tests */ email: function ({ value }) { + if (!value) { + return Promise.resolve(() => { return true }) + } + // eslint-disable-next-line const isEmail = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i return Promise.resolve(isEmail.test(value)) @@ -118,6 +122,10 @@ export default { * Rule: Value ends with one of the given Strings */ endsWith: function ({ value }, ...stack) { + if (!value) { + return Promise.resolve(() => { return true }) + } + return Promise.resolve((() => { if (typeof value === 'string' && stack.length) { return stack.find(item => { @@ -264,6 +272,10 @@ export default { * Rule: Value starts with one of the given Strings */ startsWith: function ({ value }, ...stack) { + if (!value) { + return Promise.resolve(() => { return true }) + } + return Promise.resolve((() => { if (typeof value === 'string' && stack.length) { return stack.find(item => {