#5709: modify forms.RegexField to support inverse matching
------------------------------------------------------------+---------------
Reporter: Nathan Hoover <[email protected]> | Owner:
twisty7867
Status: new | Milestone:
Component: Forms | Version:
SVN
Resolution: | Keywords:
RegexField
Stage: Design decision needed | Has_patch: 1
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
------------------------------------------------------------+---------------
Changes (by arsatiki):
* summary: modify newforms.RegexField to support inverse matching =>
modify forms.RegexField to support inverse
matching
Comment:
I encountered a generalized version of this problem today. Consider a
case, where valid data format is ''almost'' regular, but has a couple of
inconsistencies. Often it is easier to make two regexes instead of one.
First one filters out "good" stuff and the other one rejects the
exceptions.
For example, the lottery numbers around here are from 1 to 39. Matching
that with a single regex is a pain. But consider the following:
{{{
number = RegexField(r'[123]?\d', reject='(0|40)')
}}}
Or consider a badly planned urlconf after which we can't have login and
logout as usernames:
{{{
username = RegexField(<username-re>, reject=r'(login|logout)')
}}}
Certain words just aren't fit for titles:
{{{
title = RegexField('', reject='(mammaries|copulation|solids)')
}}}
Although all of the above are possible to do with some regex-magic, I feel
the use of the reject-parameter conveys the intention better than three
lines of line noise.
I'll attach a patch which adds the reject-parameter.
--
Ticket URL: <http://code.djangoproject.com/ticket/5709#comment:6>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---