Joi validation string().trim() not working
With version >= 17 of Joi you could write the schema as followed:
const localRegistrationSchema = Joi.object({ // changes here, email: Joi.string() // here .email() .trim() .lowercase() // and here .required() .messages({ 'string.email': 'Email must be a valid email address', 'string.trim': 'Email may not contain any spaces at the beginning or end', // seems to be unnecessary 'string.empty': 'Email is required' })});console.log(localRegistrationSchema.validate({ email: '' }));// error: [Error [ValidationError]: Email is required]console.log(localRegistrationSchema.validate({ email: ' foo@bar.com' }));// value: { email: 'foo@bar.com' }console.log(localRegistrationSchema.validate({ email: 'foo@bar.com ' }));// value: { email: 'foo@bar.com' }console.log(localRegistrationSchema.validate({ email: 'FOO@BAR.COM' }));// value: { email: 'foo@bar.com' }