Opened 7 years ago

Closed 6 years ago

#17355 closed Bug (invalid)

Perform proper NANP validation in US/CA localflavor phone number

Reported by: Dan McGee Owned by: nobody
Component: contrib.localflavor Version: 1.3
Severity: Normal Keywords: areacode, nanp, localflavorsplit
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


Patch attached.

Long story short:


  • NPA: 3 digits, 1st is [2-9], 2nd/3rd are [0-9]. 2 and 3 cannot both be '1'.
  • NXX: 3 digits, 1st is [2-9], 2nd/3rd are [0-9]. 2 and 3 cannot both be '1'.
  • XXXX: 4 digits, no restrictions.

Former code allowed any digit in all locations, meaning the following bogus phone numbers (now in tests as invalid) were accepted:


Attachments (1)

nanp-proper-validation.patch (4.9 KB) - added by Dan McGee 7 years ago.

Download all attachments as: .zip

Change History (4)

Changed 7 years ago by Dan McGee

comment:1 Changed 7 years ago by Dan McGee

Note that this will conflict slightly with #7463, which also makes the US and CA phone number validators stray from each other, which is likely not a good idea.

comment:2 Changed 7 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted

comment:3 Changed 6 years ago by Aymeric Augustin

Keywords: localflavorsplit added
Resolution: invalid
Status: newclosed

django.contrib.localflavor is now deprecated — see

A repository was created for each localflavor at (Replace with the country code.)

If you're still interested in this ticket, could you create a pull request on that repository?

Sorry for not resolving this issue earlier, and thanks for your input!

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