Opened 17 years ago

Last modified 14 years ago

#5709 closed

modify newforms.RegexField to support inverse matching — at Version 3

Reported by: Nathan Hoover <nathan@…> Owned by: Nathan Hoover
Component: Forms Version: dev
Severity: Keywords: RegexField
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Malcolm Tredinnick)

For conveinence, it would be nice if the RegexField supported inverse matching; i.e. the contents of the field do NOT match the regex when they're valid. I needed this in the course of using a RegexField for username signups. I have a list of undesirable usernames, like so:

INVALID_USERNAME_REGEX = '(admin|root|add|edit|administrator|service)'

Since it's not trival to make a regex that uses ^ against words rather than characters this is useful.

Change History (5)

by Nathan Hoover <nathan@…>, 17 years ago

Attachment: fields.py.diff added

diff to patch fields.py

comment:1 by Nathan Hoover <nathan@…>, 17 years ago

Owner: changed from nobody to anonymous
Status: newassigned

comment:2 by Nathan Hoover, 17 years ago

Owner: changed from anonymous to Nathan Hoover
Status: assignednew

comment:3 by Malcolm Tredinnick, 17 years ago

Description: modified (diff)

(Fixed wiki formatting in description).

I'm not sure at the moment whether this is something to add to RegexField or not, but a couple of immediate things about the patch:

  1. don't compare "== None". Instead use "is None"; it's slightly more idiomatic Python and a little more efficient.
  2. Any new parameters should go at the end of the argument list so as not to introduce backwards incompatible changes (your patch breaks any code using position arguments to RegexField).

by Nathan Hoover, 17 years ago

Attachment: fields.py.2.diff added

patch

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