-
Notifications
You must be signed in to change notification settings - Fork 4
/
validators.py
46 lines (36 loc) · 1.35 KB
/
validators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import re
from django.core.exceptions import ValidationError
from django.utils.translation import gettext as _
class NumberValidator(object):
def validate(self, password, user=None):
if not re.findall('\d', password):
raise ValidationError(
_("The password must contain at least 1 digit, 0-9."),
code='password_no_number',
)
def get_help_text(self):
return _(
"Your password must contain at least 1 digit, 0-9."
)
class UppercaseValidator(object):
def validate(self, password, user=None):
if not re.findall('[A-Z]', password):
raise ValidationError(
_("The password must contain at least 1 uppercase letter, A-Z."),
code='password_no_upper',
)
def get_help_text(self):
return _(
"Your password must contain at least 1 uppercase letter, A-Z."
)
class LowercaseValidator(object):
def validate(self, password, user=None):
if not re.findall('[a-z]', password):
raise ValidationError(
_("The password must contain at least 1 lowercase letter, a-z."),
code='password_no_lower',
)
def get_help_text(self):
return _(
"Your password must contain at least 1 lowercase letter, a-z."
)