I am trying to validate a username field and I don't want any spaces in the string. I would like to display an error back to the user.
I am using express-validator express middleware to validate the inputs. It works well for every other case but I don't know the best way to validate that there are no spaces.
https://www.npmjs.com/package/express-validator
My code
This is what I have but currently a username with spaces can be stored in the database.
check('user_name').isLength({ min: 1 }).trim().withMessage('User name is required.')
Ideally something I can use with a express-validator method.
Thank you.