-
Notifications
You must be signed in to change notification settings - Fork 0
/
fields.py
executable file
·30 lines (19 loc) · 2.12 KB
/
fields.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
# -*- coding: utf-8; -*-
import re
from django.core.validators import email_re
from django.forms import CharField, Textarea, ValidationError
from django.utils.translation import ugettext as _
email_separator_re = re.compile(r'[^\w\.\-\+@_]+')
def _is_valid_email(email):
return email_re.match(email)
class EmailsListField(CharField):
widget = Textarea
def clean(self, value):
super(EmailsListField, self).clean(value)
emails = email_separator_re.split(value)
if not emails:
raise ValidationError(_(u'Enter at least one e-mail address.'))
for email in emails:
if not _is_valid_email(email):
raise ValidationError(_('%s is not a valid e-mail address.') % email)
return emails