forked from mattbornski/libphonenumber
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.js
23 lines (18 loc) · 822 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var libphonenumber = require('libphonenumber');
var get_number = function(string, country) {
var nr_arr = string.split(',');
for (var i=0; i < nr_arr.length; i++) {
var nr = libphonenumber.phoneUtil.parseAndKeepRawInput(nr_arr[i], country || 'es');
if (libphonenumber.phoneUtil.isValidNumber(nr) ) {
return libphonenumber.phoneUtil.format(nr,1); // 1 is internationl format
}
};
}
console.log(get_number('tickets: 0161 385 3211, venue: 020 8463 2000', 'gb'));
console.log(get_number('0161 950 5000', 'gb'));
console.log(get_number('(01) 676 6170','ie'));
console.log(get_number('070 345 345','be'));
console.log(get_number('044 316 77 77','ch'));
console.log(get_number('04 67 17 69 69','fr'));
console.log(get_number('0180 / 54 81 81 81','de'));
console.log(get_number('+49 (0)30-20 60 70 80','de'));