Opened 9 years ago

Closed 8 years ago

#2307 closed defect (wontfix)

[patch] Some shortcomings of the PhoneNumberField

Reported by: anjohnson@… Owned by: nobody
Component: Validators Version:
Severity: trivial Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The PhoneNumberField type is not terribly useful as shipped:

  • It really should be called USPhoneNumberField since it won't accept international numbers, and outside of the US where numbers are 10 digits long they don't necessarily group them 3+3+4
  • The underlying database field stores 20 characters, but the admin web interface only lets me type in 12 (which admittedly is all the validator will currently accept anyhow)
  • The validator only accepts numbers in the exact form xxx-xxx-xxxx whereas other formats and separators are as common or more so in general use: (nnn) nnn-nnnn or 1-800-BISNESS are the main examples that come to mind.

I can't fix the first problem -- creating code that will recognize all national phone number formats is not really feasible, and I'm assuming that renaming the field type is also probably not possible at this stage. However I do have a short patch I will attach to this ticket that fixes the other two issues:

  • Increases the length and maxlength of the form fields to the size of the underlying database
  • Permit additional number formats to be entered such as the ones shown above.

Hope it's useful,

  • Andrew

Attachments (3)

phone.patch (2.1 KB) - added by anjohnson@… 9 years ago.
Patch to fix the shortcomings discussed in ticket.
phoneNumberField.diff (2.0 KB) - added by Wiliam Alves de Souza <wiliamsouza83@…> 8 years ago.
Other solution
regex.py (325 bytes) - added by Wiliam Alves de Souza <wiliamsouza83@…> 8 years ago.
Regular expression for national telephone numbers. Put it in .../django/core/

Download all attachments as: .zip

Change History (8)

Changed 9 years ago by anjohnson@…

Patch to fix the shortcomings discussed in ticket.

comment:1 Changed 9 years ago by anjohnson@…

  • Summary changed from Some shortcomings of the PhoneNumberField to [patch] Some shortcomings of the PhoneNumberField

Omitted [patch] from the ticket title...

comment:2 Changed 9 years ago by anonymous

I agree. phone_re should be something like this to check for international numbers.

phone_re = re.compile(r'\d?\d?\d?-?[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE)

comment:3 Changed 9 years ago by serbaut@…

I agree. However in europe we often use formats like +46 12 34 56 78 so please take this into account.

Changed 8 years ago by Wiliam Alves de Souza <wiliamsouza83@…>

Other solution

Changed 8 years ago by Wiliam Alves de Souza <wiliamsouza83@…>

Regular expression for national telephone numbers. Put it in .../django/core/

comment:4 Changed 8 years ago by Simon G. <dev@…>

  • Triage Stage changed from Unreviewed to Design decision needed

comment:5 Changed 8 years ago by russellm

  • Resolution set to wontfix
  • Status changed from new to closed

The contrib.localflavor app is designed to handle this sort of issue.

Note: See TracTickets for help on using tickets.
Back to Top