Skip to content
Advertisement

Node js Joi validation to send error if string contains space at start or end

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'))
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement