1
0
mirror of synced 2024-11-22 05:16:05 +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
*/
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 => {