Skip to content

Ticket #18775 - Fixed the Romanian phone number field validation rules #275

Closed
wants to merge 2 commits into from

3 participants

@danniel
danniel commented Aug 16, 2012

The previous version only supported 10 digit phone numbers.

This branch adds validation for:

  • normal phone numbers: 0xxxxxxxxx
  • geographic short phone numbers: 0xxxxxx
  • national short phone numbers: 1xx, 1xxxxx

I ran the Django test suite and all tests pass (under SQLite).

Original ticket: https://code.djangoproject.com/ticket/18775

@charettes charettes commented on an outdated diff Aug 16, 2012
django/contrib/localflavor/ro/forms.py
default_error_messages = {
- 'invalid': _('Phone numbers must be in XXXX-XXXXXX format.'),
+ 'invalid_length':
+ _('Phone numbers may only have 7 or 10 digits, except the ' +
+ 'national short numbers which have 3 or 6 digits'),
+ 'invalid_long_format':
+ _('Normal phone numbers (7 or 10 digits) must begin with \"0\"'),
@charettes
Django member
charettes added a note Aug 16, 2012

Are those backslashes really needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@charettes charettes commented on an outdated diff Aug 16, 2012
django/contrib/localflavor/ro/forms.py
default_error_messages = {
- 'invalid': _('Phone numbers must be in XXXX-XXXXXX format.'),
+ 'invalid_length':
+ _('Phone numbers may only have 7 or 10 digits, except the ' +
+ 'national short numbers which have 3 or 6 digits'),
+ 'invalid_long_format':
+ _('Normal phone numbers (7 or 10 digits) must begin with \"0\"'),
+ 'invalid_short_format':
+ _('National short numbers (3 or 6 digits) must begin with \"1\"'),
@charettes
Django member
charettes added a note Aug 16, 2012

Idem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@charettes charettes commented on an outdated diff Aug 16, 2012
django/contrib/localflavor/ro/forms.py
}
- def __init__(self, max_length=20, min_length=10, *args, **kwargs):
- super(ROPhoneNumberField, self).__init__(r'^[0-9\-\(\)\s]{10,20}$',
+ def __init__(self, max_length=20, min_length=3, *args, **kwargs):
+ super(ROPhoneNumberField, self).__init__(r'^[0-9\-\.\(\)\s]{3,20}$',
@charettes
Django member
charettes added a note Aug 16, 2012

It might be worth compiling the regexp in the class or module level and reuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@charettes charettes commented on an outdated diff Aug 16, 2012
django/contrib/localflavor/ro/forms.py
value = value.replace(' ','')
- if len(value) != 10:
- raise ValidationError(self.error_messages['invalid'])
+ length = len(value)
+ if length in [3, 6, 7, 10]:
@charettes
Django member
charettes added a note Aug 16, 2012

This should be a tuple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@danniel
danniel commented Aug 16, 2012

Thanks for the tips. I will update the code and resubmit the rquest.

@adrianholovaty
Django member

Hey there -- django.contrib.localflavor is now deprecated, and we're not making any more changes to it. Could you reopen this pull request for the shiny new package django-localflavor-ro? Here's the link: https://github.com/django/django-localflavor-ro

Sorry we didn't get to this pull request before the deprecation. I hope it's not too much of a pain to migrate this to the new package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.