Permalink
Browse files

9 digits phones for São Paulo/Brazil.

  • Loading branch information...
1 parent 07d70e9 commit ef5623aa55211388688b5771aca64bea1af0c017 @seocam seocam committed Jul 29, 2012
Showing with 17 additions and 4 deletions.
  1. +3 −2 django/contrib/localflavor/br/forms.py
  2. +14 −2 tests/regressiontests/localflavor/br/tests.py
@@ -15,7 +15,7 @@
from django.utils.translation import ugettext_lazy as _
-phone_digits_re = re.compile(r'^(\d{2})[-\.]?(\d{4})[-\.]?(\d{4})$')
+phone_digits_re = re.compile(r'^(\d{2})[-\.]?(\d{4,5})[-\.]?(\d{4})$')
class BRZipCodeField(RegexField):
default_error_messages = {
@@ -28,7 +28,8 @@ def __init__(self, max_length=None, min_length=None, *args, **kwargs):
class BRPhoneNumberField(Field):
default_error_messages = {
- 'invalid': _('Phone numbers must be in XX-XXXX-XXXX format.'),
+ 'invalid': _(('Phone numbers must be in either of the following '
+ 'formats: XX-XXXX-XXXX or XX-XXXXX-XXXX.')),
}
def clean(self, value):
@@ -1,3 +1,4 @@
+# -*- encoding: utf8 -*-
from __future__ import unicode_literals
from django.contrib.localflavor.br.forms import (BRZipCodeField,
@@ -62,18 +63,29 @@ def test_BRCPFField(self):
self.assertFieldOutput(BRCPFField, valid, invalid)
def test_BRPhoneNumberField(self):
- # TODO: this doesn't test for any invalid inputs.
+ error_format = [('Phone numbers must be in either of the following '
+ 'formats: XX-XXXX-XXXX or XX-XXXXX-XXXX.')]
valid = {
'41-3562-3464': '41-3562-3464',
'4135623464': '41-3562-3464',
'41 3562-3464': '41-3562-3464',
'41 3562 3464': '41-3562-3464',
'(41) 3562 3464': '41-3562-3464',
'41.3562.3464': '41-3562-3464',
+ '41.93562.3464': '41-93562-3464',
'41.3562-3464': '41-3562-3464',
' (41) 3562.3464': '41-3562-3464',
+ ' (41) 98765.3464': '41-98765-3464',
+ '(16) 91342-4325': '16-91342-4325',
+ }
+ invalid = {
+ '11-914-925': error_format,
+ '11-9144-43925': error_format,
+ '11-91342-94325': error_format,
+ '411-9134-9435': error_format,
+ '+55-41-3562-3464': error_format,
+ '41 3562–3464': error_format,
}
- invalid = {}
self.assertFieldOutput(BRPhoneNumberField, valid, invalid)
def test_BRStateSelect(self):

0 comments on commit ef5623a

Please sign in to comment.