Opened 18 years ago

Closed 17 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: no UI/UX: no

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@… 18 years ago.
Patch to fix the shortcomings discussed in ticket.
phoneNumberField.diff (2.0 KB ) - added by Wiliam Alves de Souza <wiliamsouza83@…> 18 years ago.
Other solution
regex.py (325 bytes ) - added by Wiliam Alves de Souza <wiliamsouza83@…> 18 years ago.
Regular expression for national telephone numbers. Put it in .../django/core/

Download all attachments as: .zip

Change History (8)

by anjohnson@…, 18 years ago

Attachment: phone.patch added

Patch to fix the shortcomings discussed in ticket.

comment:1 by anjohnson@…, 18 years ago

Summary: Some shortcomings of the PhoneNumberField[patch] Some shortcomings of the PhoneNumberField

Omitted [patch] from the ticket title...

comment:2 by anonymous, 18 years ago

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 by serbaut@…, 18 years ago

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

by Wiliam Alves de Souza <wiliamsouza83@…>, 18 years ago

Attachment: phoneNumberField.diff added

Other solution

by Wiliam Alves de Souza <wiliamsouza83@…>, 18 years ago

Attachment: regex.py added

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

comment:4 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedDesign decision needed

comment:5 by Russell Keith-Magee, 17 years ago

Resolution: wontfix
Status: newclosed

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

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