A validator to validate the given value whether match regex or not.
| 21 | |
| 22 | |
| 23 | class RegexValidator(Validator): |
| 24 | """ |
| 25 | A validator to validate the given value whether match regex or not. |
| 26 | """ |
| 27 | |
| 28 | def __init__(self, pattern: str, flags: int | re.RegexFlag) -> None: |
| 29 | self.regex = re.compile(pattern, flags) |
| 30 | |
| 31 | def __call__(self, value: Any) -> None: |
| 32 | if not self.regex.match(value): |
| 33 | raise ValidationError(f"Value '{value}' does not match regex '{self.regex.pattern}'") |
| 34 | |
| 35 | |
| 36 | class MaxLengthValidator(Validator): |
no outgoing calls
no test coverage detected
searching dependent graphs…