1
0
mirror of synced 2024-11-25 14:56:03 +03:00

email, startsWith and endsWith validators now return valid result if value is empty

This commit is contained in:
1on 2020-05-25 13:42:40 +03:00
parent 15ec7c7743
commit 2b26ab85c7

View File

@ -109,6 +109,10 @@ export default {
* Rule: tests * Rule: tests
*/ */
email: function ({ value }) { email: function ({ value }) {
if (!value) {
return Promise.resolve(() => { return true })
}
// eslint-disable-next-line // eslint-disable-next-line
const isEmail = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i const isEmail = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i
return Promise.resolve(isEmail.test(value)) return Promise.resolve(isEmail.test(value))
@ -118,6 +122,10 @@ export default {
* Rule: Value ends with one of the given Strings * Rule: Value ends with one of the given Strings
*/ */
endsWith: function ({ value }, ...stack) { endsWith: function ({ value }, ...stack) {
if (!value) {
return Promise.resolve(() => { return true })
}
return Promise.resolve((() => { return Promise.resolve((() => {
if (typeof value === 'string' && stack.length) { if (typeof value === 'string' && stack.length) {
return stack.find(item => { return stack.find(item => {
@ -264,6 +272,10 @@ export default {
* Rule: Value starts with one of the given Strings * Rule: Value starts with one of the given Strings
*/ */
startsWith: function ({ value }, ...stack) { startsWith: function ({ value }, ...stack) {
if (!value) {
return Promise.resolve(() => { return true })
}
return Promise.resolve((() => { return Promise.resolve((() => {
if (typeof value === 'string' && stack.length) { if (typeof value === 'string' && stack.length) {
return stack.find(item => { return stack.find(item => {