Created
August 6, 2020 01:54
-
-
Save pipopotamasu/b0eb126c711176f84316ccf052bbb213 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validateDuplicatedEmail(email) { | |
const { users } = this.from[1].value; | |
if (users.length < 2) return true; | |
let dupCount = 0; | |
for (let i = 0; i < users.length; i += 1) { | |
if (users[i].email === email) { | |
dupCount += 1; | |
if (dupCount > 1) { | |
return false; | |
} | |
} | |
} | |
return true; | |
} | |
const schema = yup.object().shape({ | |
users: yup.array( | |
yup.object().shape({ | |
name: yup.string().required('name is required.'), | |
email: yup | |
.string() | |
.required('email is required.') | |
.email('invalid email type.') | |
.test('email-dup', 'duplicated email', validateDuplicatedEmail) | |
}), | |
), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment