Skip to content

Commit

Permalink
Merge pull request #1070 from jordanbtucker/patch-1
Browse files Browse the repository at this point in the history
Update `string.regex` examples
  • Loading branch information
Marsup committed Dec 18, 2016
2 parents 7ad8a4e + bf804fc commit 045b99c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1572,16 +1572,16 @@ Defines a regular expression rule where:
```js
const schema = Joi.string().regex(/^[abc]+$/);

const inlineNamedSchema = Joi.string().regex(/[0-9]/, 'numbers');
const inlineNamedSchema = Joi.string().regex(/^[0-9]+$/, 'numbers');
inlineNamedSchema.validate('alpha'); // ValidationError: "value" with value "alpha" fails to match the numbers pattern

const namedSchema = Joi.string().regex(/[0-9]/, { name: 'numbers'});
const namedSchema = Joi.string().regex(/^[0-9]+$/, { name: 'numbers'});
namedSchema.validate('alpha'); // ValidationError: "value" with value "alpha" fails to match the numbers pattern

const invertedSchema = Joi.string().regex(/[a-z]/, { invert: true });
const invertedSchema = Joi.string().regex(/^[a-z]+$/, { invert: true });
invertedSchema.validate('lowercase'); // ValidationError: "value" with value "lowercase" matches the inverted pattern: [a-z]

const invertedNamedSchema = Joi.string().regex(/[a-z]/, { name: 'alpha', invert: true });
const invertedNamedSchema = Joi.string().regex(/^[a-z]+$/, { name: 'alpha', invert: true });
invertedNamedSchema.validate('lowercase'); // ValidationError: "value" with value "lowercase" matches the inverted alpha pattern
```
Expand Down

0 comments on commit 045b99c

Please sign in to comment.