Opened 4 years ago

Closed 3 years ago

#17355 closed Bug (invalid)

Perform proper NANP validation in US/CA localflavor phone number

Reported by: toofishes 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 toofishes 4 years ago.

Download all attachments as: .zip

Change History (4)

Changed 4 years ago by toofishes

comment:1 Changed 4 years ago by toofishes

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 4 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 3 years ago by aaugustin

  • Keywords localflavorsplit added
  • Resolution set to invalid
  • Status changed from new to closed

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