Code

Ticket #7463: 7463.diff

File 7463.diff, 1.5 KB (added by mlavin, 2 years ago)

Updated patch with tests.

Line 
1diff --git a/django/contrib/localflavor/us/forms.py b/django/contrib/localflavor/us/forms.py
2--- a/django/contrib/localflavor/us/forms.py
3+++ b/django/contrib/localflavor/us/forms.py
4@@ -13,7 +13,7 @@
5 from django.utils.translation import ugettext_lazy as _
6 
7 
8-phone_digits_re = re.compile(r'^(?:1-?)?(\d{3})[-\.]?(\d{3})[-\.]?(\d{4})$')
9+phone_digits_re = re.compile(r'^(?:1-?)?(\d{3})[-/\.]?(\d{3})[-\.]?(\d{4})$')
10 ssn_re = re.compile(r"^(?P<area>\d{3})[-\ ]?(?P<group>\d{2})[-\ ]?(?P<serial>\d{4})$")
11 
12 class USZipCodeField(RegexField):
13@@ -34,7 +34,7 @@
14         super(USPhoneNumberField, self).clean(value)
15         if value in EMPTY_VALUES:
16             return u''
17-        value = re.sub('(\(|\)|\s+)', '', smart_unicode(value))
18+        value = re.sub('(\(|\)|/|\s+)', '', smart_unicode(value))
19         m = phone_digits_re.search(value)
20         if m:
21             return u'%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
22diff --git a/tests/regressiontests/localflavor/us/tests.py b/tests/regressiontests/localflavor/us/tests.py
23--- a/tests/regressiontests/localflavor/us/tests.py
24+++ b/tests/regressiontests/localflavor/us/tests.py
25@@ -253,6 +253,9 @@
26             '312.555.1212': '312-555-1212',
27             '312.555-1212': '312-555-1212',
28             ' (312) 555.1212 ': '312-555-1212',
29+            '312/555.1212 ': '312-555-1212',
30+            '312/555 1212 ': '312-555-1212',
31+            '312/555-1212 ': '312-555-1212',
32         }
33         invalid = {
34             '555-1212': error_format,