Code

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#269 closed enhancement (fixed)

Patch: validator that matches against a regular expression

Reported by: hugo <gb@…> Owned by: adrian
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: UI/UX:

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.

Attachments (0)

Change History (3)

comment:1 Changed 9 years ago by hugo <gb@…>

  • Summary changed from validator that matches against a regular expression to Patch: validator that matches against a regular expression

comment:2 Changed 9 years ago by adrian

  • Status changed from new to assigned

comment:3 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from assigned to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.