Skip to content

Commit

Permalink
Update API.md with string.regex invalidate config
Browse files Browse the repository at this point in the history
  • Loading branch information
WesTyler committed Nov 14, 2016
1 parent 83b1aa7 commit c5f95af
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1542,14 +1542,26 @@ const schema = Joi.object({
});
```
#### `string.regex(pattern, [name])`
#### `string.regex(pattern, [name | config])`
Defines a regular expression rule where:
- `pattern` - a regular expression object the string value must match against.
- `name` - optional name for patterns (useful with multiple patterns). Defaults to 'required'.
- `config` - an optional configuration object with the following supported properties:
- `name` - optional pattern name. Defaults to `required`.
- `invalidate` - optional boolean flag. Defaults to `false` behavior. If specified as `true`, the provided pattern will be disallowed instead of required.
```js
const schema = Joi.string().regex(/^[abc]+$/);

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

const invalidatedSchema = Joi.string().regex(/[a-z]/, { invalidate: true });
invalidatedSchema.validate('lowercase'); // ValidationError: "value" with value "lowercase" matches the invalidated pattern: [a-z]

const invalidatedNamedSchema = Joi.string().regex(/[a-z]/, { name: 'alpha', invalidate: true });
invalidatedNamedSchema.validate('lowercase'); // ValidationError: "value" with value "lowercase" matches the invalidated alpha pattern
```
#### `string.replace(pattern, replacement)`
Expand Down

0 comments on commit c5f95af

Please sign in to comment.