core.validators.RegexValidator

class RegexValidator(regex=None, message=None, code=None, inverse_match=None, flags=0) [source]

Parameters:
  • regex – If not None, overrides regex. Can be a regular expression string or a pre-compiled regular expression.
  • message – If not None, overrides message.
  • code – If not None, overrides code.
  • inverse_match – If not None, overrides inverse_match.
  • flags – If not None, overrides flags. In that case, regex must be a regular expression string, or TypeError is raised.
regex

The regular expression pattern to search for the provided value, or a pre-compiled regular expression. By default, raises a ValidationError with message and code if a match is not found. That standard behavior can be reversed by setting inverse_match to True, in which case the ValidationError is raised when a match is found. By default, matches any string (including an empty string).

message

The error message used by ValidationError if validation fails. Defaults to "Enter a valid value".

code

The error code used by ValidationError if validation fails. Defaults to "invalid".

inverse_match

The match mode for regex. Defaults to False.

flags

The flags used when compiling the regular expression string regex. If regex is a pre-compiled regular expression, and flags is overridden, TypeError is raised. Defaults to 0.

doc_Django
2016-10-09 18:35:02
Comments
Leave a Comment

Please login to continue.