Ticket #7463: 7463.diff

File 7463.diff, 1.5 KB (added by Mark Lavin, 12 years ago)

Updated patch with tests.

  • django/contrib/localflavor/us/forms.py

    diff --git a/django/contrib/localflavor/us/forms.py b/django/contrib/localflavor/us/forms.py
    a b  
    1313from django.utils.translation import ugettext_lazy as _
    1414
    1515
    16 phone_digits_re = re.compile(r'^(?:1-?)?(\d{3})[-\.]?(\d{3})[-\.]?(\d{4})$')
     16phone_digits_re = re.compile(r'^(?:1-?)?(\d{3})[-/\.]?(\d{3})[-\.]?(\d{4})$')
    1717ssn_re = re.compile(r"^(?P<area>\d{3})[-\ ]?(?P<group>\d{2})[-\ ]?(?P<serial>\d{4})$")
    1818
    1919class USZipCodeField(RegexField):
     
    3434        super(USPhoneNumberField, self).clean(value)
    3535        if value in EMPTY_VALUES:
    3636            return u''
    37         value = re.sub('(\(|\)|\s+)', '', smart_unicode(value))
     37        value = re.sub('(\(|\)|/|\s+)', '', smart_unicode(value))
    3838        m = phone_digits_re.search(value)
    3939        if m:
    4040            return u'%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
  • tests/regressiontests/localflavor/us/tests.py

    diff --git a/tests/regressiontests/localflavor/us/tests.py b/tests/regressiontests/localflavor/us/tests.py
    a b  
    253253            '312.555.1212': '312-555-1212',
    254254            '312.555-1212': '312-555-1212',
    255255            ' (312) 555.1212 ': '312-555-1212',
     256            '312/555.1212 ': '312-555-1212',
     257            '312/555 1212 ': '312-555-1212',
     258            '312/555-1212 ': '312-555-1212',
    256259        }
    257260        invalid = {
    258261            '555-1212': error_format,
Back to Top