showing results for - "joi validation custom message in node"
Luigi
10 Aug 2018
1const Joi = require('Joi');
2
3const schema = Joi.object({
4    username: Joi.string()
5      .min(2)
6      .max(30)
7      .required()
8      .pattern(new RegExp(/^(?!.*\.\.)(?!.*\.$)[^\W][\w.]{0,29}$/))
9      .message({"string.pattern.base":"Invalid username",
10                "string.min":"minimum 2 character required",
11                "string.max":"maximum 30 characters allowed"})
12});
13//
14messages: {
15      'any.custom': [Object],
16      'any.default': [Object],
17      'any.failover': [Object],
18      'any.invalid': [Object],
19      'any.only': [Object],
20      'any.ref': [Object],
21      'any.required': [Object],
22      'any.unknown': [Object],
23      'string.alphanum': [Object],
24      'string.base': [Object],
25      'string.base64': [Object],
26      'string.creditCard': [Object],
27      'string.dataUri': [Object],
28      'string.domain': [Object],
29      'string.email': [Object],
30      'string.empty': [Object],
31      'string.guid': [Object],
32      'string.hex': [Object],
33      'string.hexAlign': [Object],
34      'string.hostname': [Object],
35      'string.ip': [Object],
36      'string.ipVersion': [Object],
37      'string.isoDate': [Object],
38      'string.isoDuration': [Object],
39      'string.length': [Object],
40      'string.lowercase': [Object],
41      'string.max': [Object],
42      'string.min': [Object],
43      'string.normalize': [Object],
44      'string.token': [Object],
45      'string.pattern.base': [Object],
46      'string.pattern.name': [Object],
47      'string.pattern.invert.base': [Object],
48      'string.pattern.invert.name': [Object],
49      'string.trim': [Object],
50      'string.uri': [Object],
51      'string.uriCustomScheme': [Object],
52      'string.uriRelativeOnly': [Object],
53      'string.uppercase': [Object]
54}
55//$uj@y