Code

Ticket #12613: phone2numeric_complete.diff

File phone2numeric_complete.diff, 1.1 KB (added by gabrielhurley, 4 years ago)

Adds support for Q and Z in the phone2numeric function.

Line 
1Index: django/utils/text.py
2===================================================================
3--- django/utils/text.py        (revision 12228)
4+++ django/utils/text.py        (working copy)
5@@ -157,12 +157,12 @@
6 
7 def phone2numeric(phone):
8     "Converts a phone number with letters into its numeric equivalent."
9-    letters = re.compile(r'[A-PR-Y]', re.I)
10-    char2number = lambda m: {'a': '2', 'c': '2', 'b': '2', 'e': '3',
11-         'd': '3', 'g': '4', 'f': '3', 'i': '4', 'h': '4', 'k': '5',
12-         'j': '5', 'm': '6', 'l': '5', 'o': '6', 'n': '6', 'p': '7',
13-         's': '7', 'r': '7', 'u': '8', 't': '8', 'w': '9', 'v': '8',
14-         'y': '9', 'x': '9'}.get(m.group(0).lower())
15+    letters = re.compile(r'[A-Z]', re.I)
16+    char2number = lambda m: {'a': '2', 'b': '2', 'c': '2', 'd': '3', 'e': '3',
17+         'f': '3', 'g': '4', 'h': '4', 'i': '4', 'j': '5', 'k': '5', 'l': '5',
18+         'm': '6', 'n': '6', 'o': '6', 'p': '7', 'q': '7', 'r': '7', 's': '7',
19+         't': '8', 'u': '8', 'v': '8', 'w': '9', 'x': '9', 'y': '9', 'z': '9',
20+        }.get(m.group(0).lower())
21     return letters.sub(char2number, phone)
22 phone2numeric = allow_lazy(phone2numeric)
23