Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#269 closed enhancement (fixed)

Patch: validator that matches against a regular expression

Reported by: hugo <gb@…> Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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)

comment:1 by hugo <gb@…>, 19 years ago

Summary: validator that matches against a regular expressionPatch: validator that matches against a regular expression

comment:2 by Adrian Holovaty, 19 years ago

Status: newassigned

comment:3 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: assignedclosed

(In [399]) Fixed #269 -- Added MatchesRegularExpression validator. Thanks, Hugo!

Note: See TracTickets for help on using tickets.
Back to Top