-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathGBR.coffee
199 lines (188 loc) · 8.45 KB
/
GBR.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
Phone = require('../Phone')
PhoneNumber = require('../PhoneNumber')
# For more info check:
# http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers#Formatting_GB_telephone_numbers
# list of area codes from:
# http://consumers.ofcom.org.uk/phone/numbering/telephone-area-codes-tool/
class UnitedKingdom
constructor: ->
@countryName = "United Kingdom"
@countryNameAbbr = "GBR"
@countryCode = '44'
@regex = /^(?:(?:(?:\+|)(?:44|)|))(?:0|)(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{5}\)?[\s-]?\d{4,5}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$/
@mobileRegex = /^7(?:[1-4]\d\d|5(?:0[0-8]|[13-9]\d|2[0-35-9])|624|7(?:0[1-9]|[1-7]\d|8[02-9]|9[0-689])|8(?:[014-9]\d|[23][0-8])|9(?:[04-9]\d|1[02-9]|2[0-35-9]|3[0-689]))\d{6}$/
@splitRegexs =
[{
#Ranges 2d, 55, 56, 70, 76 (excluding 7624) with 10 digits
validLengths: [10]
leadingDigits: /^(?:2|5[56]|7(?:0|6(?:[013-9]|2[0-35-9])))/,
pattern: /^(\d{2})(\d{4})(\d{4})$/,
format: "$1 $2 $3"
},{
#Ranges 11d, 1d1, 3dd, 9dd with 10 digits
validLengths: [10]
leadingDigits: /^(?:1(?:1|\d1)|3[0347]|9[018])/,
pattern: /^(\d{3})(\d{3})(\d{4})$/,
format: "$1 $2 $3"
},{
#Ranges 1dddd with 9 or 10 digits
validLengths: [9, 10]
leadingDigits: /^(?:1(?:3873|5(?:242|39[456])|697[347]|768[347]|9467))/,
pattern: /^(\d{5})(\d{4,5})$/,
format: "$1 $2"
},{
#Ranges 1ddd with 9 or 10 digits
validLengths: [9, 10]
leadingDigits: /^1/,
pattern: /^(1\d{3})(\d{5,6})$/,
format: "$1 $2"
},{
#Ranges 7ddd (including 7624) (not 70, 76) with 10 digits
validLengths: [10]
leadingDigits: /^7(?:[1-5789]|624)/,
pattern: /^(7\d{3})(\d{6})$/,
format: "$1 $2"
},{
#Ranges 800 1111 with 7 digits : UK ChildLine
validLengths: [7]
leadingDigits: /^8001111/,
pattern: /^(800)(\d{4})$/,
format: "$1 $2"
},{
#Ranges 845 46 47 with 7 digits : UK NHS Direct
validLengths: [7]
leadingDigits: /^84546\d/,
pattern: /^(845)(46)(4\d)$/,
format: "$1 $2 $3"
},{
#Ranges 84d, 87d with 10 digits
validLengths: [10]
leadingDigits: /^8(?:4[2-5]|7[0-3])/,
pattern: /^(8\d{2})(\d{3})(\d{4})$/,
format: "$1 $2 $3"
},{
#Ranges 80d (including 800) with 10 digits
validLengths: [10]
leadingDigits: /^80[08]/,
pattern: /^(80\d)(\d{3})(\d{4})$/,
format: "$1 $2 $3"
},{
#Ranges 500, 800 with 9 digits
validLengths: [9]
leadingDigits: /^[58]00/,
pattern: /^([58]00)(\d{6})$/,
format: "$1 $2"
}]
@optionalTrunkPrefix = '0'
@nationalNumberSeparator = ' '
@nationalDestinationCode = [
"20", "22", "23", "24", "28", "29"
"113", "114", "115", "116", "117", "118", "1200",
"1202", "1204", "1205", "1206", "1207", "1208", "1209",
"121", "1223", "1224", "1225", "1226", "1227", "1228",
"1229", "1233", "1234", "1235", "1236", "1237", "1239",
"1241", "1242", "1243", "1244", "1245", "1246", "1248",
"1249", "1250", "1252", "1253", "1254", "1255", "1256",
"1257", "1258", "1259", "1260", "1261", "1262", "1263",
"1264", "1267", "1268", "1269", "1270", "1271", "1273",
"1274", "1275", "1276", "1277", "1278", "1279", "1280",
"1282", "1283", "1284", "1285", "1286", "1287", "1288",
"1289", "1290", "1291", "1292", "1293", "1294", "1295",
"1296", "1297", "1298", "1299", "1300", "1301", "1302",
"1303", "1304", "1305", "1306", "1307", "1308", "1309",
"131", "1320", "1322", "1323", "1324", "1325", "1326",
"1327", "1328", "1329", "1330", "1332", "1333", "1334",
"1335", "1337", "1339", "1340", "1341", "1342", "1343",
"1344", "1346", "1347", "1348", "1349", "1350", "1352",
"1353", "1354", "1355", "1356", "1357", "1358", "1359",
"1360", "1361", "1362", "1363", "1364", "1366", "1367",
"1368", "1369", "1371", "1372", "1373", "1375", "1376",
"1377", "1379", "1380", "1381", "1382", "1383", "1384",
"1386", "1387", "13873", "1388", "1389", "1392", "1394",
"1395", "1397", "1398", "1400", "1403", "1404", "1405",
"1406", "1407", "1408", "1409", "141", "1420", "1422",
"1423", "1424", "1425", "1427", "1428", "1429", "1430",
"1431", "1432", "1433", "1434", "1435", "1436", "1437",
"1438", "1439", "1440", "1442", "1443", "1444", "1445",
"1446", "1449", "1450", "1451", "1452", "1453", "1454",
"1455", "1456", "1457", "1458", "1460", "1461", "1462",
"1463", "1464", "1465", "1466", "1467", "1469", "1470",
"1471", "1472", "1473", "1474", "1475", "1476", "1477",
"1478", "1479", "1480", "1481", "1482", "1483", "1484",
"1485", "1487", "1488", "1489", "1490", "1491", "1492",
"1493", "1494", "1495", "1496", "1497", "1499", "1501",
"1502", "1503", "1505", "1506", "1507", "1508", "1509",
"151", "1520", "1522", "1524", "15242", "1525", "1526",
"1527", "1528", "1529", "1530", "1531", "1534", "1535",
"1536", "1538", "1539", "15394", "15395", "15396", "1540",
"1542", "1543", "1544", "1545", "1546", "1547", "1548",
"1549", "1550", "1553", "1554", "1555", "1556", "1557",
"1558", "1559", "1560", "1561", "1562", "1563", "1564",
"1565", "1566", "1567", "1568", "1569", "1570", "1571",
"1572", "1573", "1575", "1576", "1577", "1578", "1579",
"1580", "1581", "1582", "1583", "1584", "1586", "1588",
"1590", "1591", "1592", "1593", "1594", "1595", "1597",
"1598", "1599", "1600", "1603", "1604", "1606", "1608",
"1609", "161", "1620", "1621", "1622", "1623", "1624",
"1625", "1626", "1628", "1629", "1630", "1631", "1633",
"1634", "1635", "1636", "1637", "1638", "1639", "1641",
"1642", "1643", "1644", "1646", "1647", "1650", "1651",
"1652", "1653", "1654", "1655", "1656", "1659", "1661",
"1663", "1664", "1665", "1666", "1667", "1668", "1669",
"1670", "1671", "1672", "1673", "1674", "1675", "1676",
"1677", "1678", "1680", "1681", "1683", "1684", "1685",
"1686", "1687", "1688", "1689", "1690", "1691", "1692",
"1694", "1695", "1697", "16973", "16974", "1698", "1700",
"1702", "1704", "1706", "1707", "1708", "1709", "1720",
"1721", "1722", "1723", "1724", "1725", "1726", "1727",
"1728", "1729", "1730", "1732", "1733", "1736", "1737",
"1738", "1740", "1743", "1744", "1745", "1746", "1747",
"1748", "1749", "1750", "1751", "1752", "1753", "1754",
"1756", "1757", "1758", "1759", "1760", "1761", "1763",
"1764", "1765", "1766", "1767", "1768", "17683", "17684",
"17687", "1769", "1770", "1771", "1772", "1773", "1775",
"1776", "1777", "1778", "1779", "1780", "1782", "1784",
"1785", "1786", "1787", "1788", "1789", "1790", "1792",
"1793", "1794", "1795", "1796", "1797", "1798", "1799",
"1803", "1805", "1806", "1807", "1808", "1809", "1821",
"1822", "1823", "1824", "1825", "1827", "1828", "1829",
"1830", "1832", "1833", "1834", "1835", "1837", "1838",
"1840", "1841", "1842", "1843", "1844", "1845", "1847",
"1848", "1851", "1852", "1854", "1855", "1856", "1857",
"1858", "1859", "1862", "1863", "1864", "1865", "1866",
"1869", "1870", "1871", "1872", "1873", "1874", "1875",
"1876", "1877", "1878", "1879", "1880", "1882", "1883",
"1884", "1885", "1886", "1887", "1888", "1889", "1890",
"1892", "1895", "1896", "1899", "1900", "1902", "1903",
"1904", "1905", "1908", "1909", "191", "1920", "1922",
"1923", "1924", "1925", "1926", "1928", "1929", "1931",
"1932", "1933", "1934", "1935", "1937", "1938", "1939",
"1942", "1943", "1944", "1945", "1946", "19467", "1947",
"1948", "1949", "1950", "1951", "1952", "1953", "1954",
"1955", "1957", "1959", "1962", "1963", "1964", "1967",
"1968", "1969", "1970", "1971", "1972", "1974", "1975",
"1977", "1978", "1980", "1981", "1982", "1983", "1984",
"1985", "1986", "1987", "1988", "1989", "1992", "1993",
"1994", "1995", "1997"
]
specialRules: (withoutCountryCode, withoutNDC, ndc) =>
phone = new PhoneNumber(@countryNameAbbr, @countryCode, ndc, withoutNDC)
if withoutNDC.length is 10 and @mobileRegex.test(withoutNDC)
phone.isMobile = true
return phone
splitNumber: (number) =>
findSplitter = do ->
(nmbr, splitRegexs) ->
for potentialSplitGrp in splitRegexs
if nmbr.length in potentialSplitGrp.validLengths and potentialSplitGrp.leadingDigits.test(nmbr)
return potentialSplitGrp
splitter = findSplitter(number, @splitRegexs)
if splitter
return Phone.compact number.split(splitter.pattern)
else
return [number]
# register
uk = new UnitedKingdom()
Phone.countries['44'] = uk
# exports
module.exports = uk