mirror of
https://github.com/django/django.git
synced 2025-07-07 03:09:22 +00:00
[soc2009/model-validation] Changed EmailField to use validators
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11034 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3772800752
commit
d707d37048
@ -451,19 +451,11 @@ class RegexField(CharField):
|
|||||||
if not self.regex.search(value):
|
if not self.regex.search(value):
|
||||||
raise ValidationError(self.error_messages['invalid'])
|
raise ValidationError(self.error_messages['invalid'])
|
||||||
|
|
||||||
email_re = re.compile(
|
class EmailField(CharField):
|
||||||
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
|
|
||||||
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
|
|
||||||
r')@(?:[A-Z0-9]+(?:-*[A-Z0-9]+)*\.)+[A-Z]{2,6}$', re.IGNORECASE) # domain
|
|
||||||
|
|
||||||
class EmailField(RegexField):
|
|
||||||
default_error_messages = {
|
default_error_messages = {
|
||||||
'invalid': _(u'Enter a valid e-mail address.'),
|
'invalid': _(u'Enter a valid e-mail address.'),
|
||||||
}
|
}
|
||||||
|
default_validators = [validators.validate_email]
|
||||||
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
|
|
||||||
RegexField.__init__(self, email_re, max_length, min_length, *args,
|
|
||||||
**kwargs)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
Loading…
x
Reference in New Issue
Block a user