1 | 7c7
|
---|
2 | < from django.forms.fields import Field, RegexField, Select, CharField
|
---|
3 | ---
|
---|
4 | > from django.forms.fields import Field, RegexField, Select
|
---|
5 | 10d9
|
---|
6 | < from django.utils.translation import ugettext_lazy as _
|
---|
7 | 14d12
|
---|
8 | <
|
---|
9 | 58,74d55
|
---|
10 | <
|
---|
11 | < phone_digits_re = re.compile(r'^0\d{2,4}[-\s]{1}[1-9]\d{6}$')
|
---|
12 | <
|
---|
13 | < class INPhoneNumberField(CharField):
|
---|
14 | < default_error_messages = {
|
---|
15 | < 'invalid': _('Phone numbers must be in 0STD-XXXXXXX or 0STD XXXXXXX format.'),
|
---|
16 | < }
|
---|
17 | <
|
---|
18 | < def clean(self, value):
|
---|
19 | < super(INPhoneNumberField, self).clean(value)
|
---|
20 | < if value in EMPTY_VALUES:
|
---|
21 | < return u''
|
---|
22 | < value = smart_unicode(value)
|
---|
23 | < m = phone_digits_re.match(value)
|
---|
24 | < if m:
|
---|
25 | < return u'%s' % (value)
|
---|
26 | < raise ValidationError(self.error_messages['invalid'])
|
---|