diff options
| author | Claude Paroz <claude@2xlibre.net> | 2016-04-22 19:39:13 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2016-05-16 19:37:57 +0200 |
| commit | 526575c64150e10dd8666d1ed3f86eedd00df2ed (patch) | |
| tree | 175e0889a9ef03f53ed9273fb659918eea01fe2d /django/contrib/auth/validators.py | |
| parent | 2265ff3710ae244a6f01640972571979543282c6 (diff) | |
Fixed #21379 -- Created auth-specific username validators
Thanks Tim Graham for the review.
Diffstat (limited to 'django/contrib/auth/validators.py')
| -rw-r--r-- | django/contrib/auth/validators.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/django/contrib/auth/validators.py b/django/contrib/auth/validators.py new file mode 100644 index 0000000000..0691d22a88 --- /dev/null +++ b/django/contrib/auth/validators.py @@ -0,0 +1,26 @@ +import re + +from django.core import validators +from django.utils import six +from django.utils.deconstruct import deconstructible +from django.utils.translation import ugettext_lazy as _ + + +@deconstructible +class ASCIIUsernameValidator(validators.RegexValidator): + regex = r'^[\w.@+-]+$' + message = _( + 'Enter a valid username. This value may contain only English letters, ' + 'numbers, and @/./+/-/_ characters.' + ) + flags = re.ASCII if six.PY3 else 0 + + +@deconstructible +class UnicodeUsernameValidator(validators.RegexValidator): + regex = r'^[\w.@+-]+$' + message = _( + 'Enter a valid username. This value may contain only letters, ' + 'numbers, and @/./+/-/_ characters.' + ) + flags = re.UNICODE if six.PY2 else 0 |
