How to create JOI validation with Node js if string contains empty space at start or end send error
example : if input is
name = "test123" //valid
name = "test(space)" or "(space)test" // invalid
You can use a regex pattern to check that string does not start or end with space.
Joi.string().pattern(new RegExp('^[^\s][^\s]+$', 'g'))
You can use below regex to validate the your cases
Joi.string().pattern(new RegExp('^([a-zA-Z0-9]+( [a-zA-Z0-9]+)*)$', 'g'))