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
Advertisement
Answer
You can use below regex to validate the your cases
Joi.string().pattern(new RegExp('^([a-zA-Z0-9]+( [a-zA-Z0-9]+)*)$', 'g'))