email, startsWith and endsWith validators now return valid result if value is empty
This commit is contained in:
parent
15ec7c7743
commit
2b26ab85c7
@ -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 => {
|
||||||
|
Loading…
Reference in New Issue
Block a user