validators.py 663 B

12345678910111213141516171819202122232425
  1. import re
  2. from django.core import validators
  3. from django.utils.deconstruct import deconstructible
  4. from django.utils.translation import gettext_lazy as _
  5. @deconstructible
  6. class ASCIIUsernameValidator(validators.RegexValidator):
  7. regex = r'^[\w]+\Z'
  8. message = _(
  9. 'Enter a valid username. This value may contain only English letters, '
  10. 'numbers, and _ characters.'
  11. )
  12. flags = re.ASCII
  13. @deconstructible
  14. class UnicodeUsernameValidator(validators.RegexValidator):
  15. regex = r'^[\w]+\Z'
  16. message = _(
  17. 'Enter a valid username. This value may contain only letters, '
  18. 'numbers, and _ characters.'
  19. )
  20. flags = 0