Patch: validator that matches against a regular expression
For some cases it's easies to have a validator that just matches against some given regular expression:
class MatchesRegularExpression:
def __init__(self, regexp, error_message="The format for this field is wrong"):
self.regexp = regexp
self.error_message = error_message
def __call__(self, field_data, all_data):
if not self.regexp.match(field_data):
raise validators.ValidationError(self.error_message)
This is actually a validator factory that produces the validator on instantiation.
Change History
(3)
Summary: |
validator that matches against a regular expression → Patch: validator that matches against a regular expression
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
(In [399]) Fixed #269 -- Added MatchesRegularExpression validator. Thanks, Hugo!