使用trim和min:
const schema = Joi
.string()
.trim()
.min(1)
.required();
Run Code Online (Sandbox Code Playgroud)
测试:
console.log(schema.validate(' ')); // "value" is not allowed to be empty
console.log(schema.validate('')); // "value" is not allowed to be empty
console.log(schema.validate(' foo')); // value: 'foo'
console.log(schema.validate('foo ')); // value: 'foo'
Run Code Online (Sandbox Code Playgroud)