Posts

How to make Joi regex() validation fail if the string contains “ ” (whitespace)?

Image
0 I have the a vehicle registration number being validated by Joi in Node.js and need it to reject any string that contains whitespace (space, tab, etc.) I tried the following schema, but Joi does let it go through: const schema = { regNo: Joi.string() .regex(/^.*S*.*$/) .required() .trim() } So, if I submit "JOI 777" the string is considered valid. What am I doing wrong? Thanks in advance, javascript node.js joi share | improve this question asked Nov 20 '18 at 11:47 Nikolay Chekan Nikolay Chekan 3 1 ...