1var validateEmail = function(email) {
2 var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
3 return re.test(email)
4};
5
6var EmailSchema = new Schema({
7 email: {
8 type: String,
9 trim: true,
10 lowercase: true,
11 unique: true,
12 required: 'Email address is required',
13 validate: [validateEmail, 'Please fill a valid email address'],
14 match: [/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/, 'Please fill a valid email address']
15 }
16});
1import { isEmail } from 'validator';
2// ...
3
4const EmailSchema = new Schema({
5 email: {
6 //... other setup
7 validate: [ isEmail, 'invalid email' ]
8 }
9});