Opened 17 years ago
Last modified 14 years ago
#5709 closed
modify newforms.RegexField to support inverse matching — at Version 3
Reported by: | 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 )
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 , 17 years ago
Attachment: | fields.py.diff added |
---|
comment:1 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:3 by , 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:
- don't compare "== None". Instead use "is None"; it's slightly more idiomatic Python and a little more efficient.
- 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).
diff to patch fields.py