Reputation: 556
how can i write a regex to find a phone number
this is a number 09876 09875
it should detect 09876 09875 as a whole number
this is a number +17865 8658 u98765
this should detect two numbers +17865 8658 and 98765
Upvotes: 0
Views: 189
Reputation: 152206
Remove spaces and match plus sign with following numbers:
var input = 'this is a number +17865 8658 u98765',
outputs = input.replace(/ /g, '').match(/\+?\d+/g);
Output:
["+178658658", "98765"]
Without replacing spaces:
var input = 'this is a number +17865 8658 u98765',
outputs = input.match(/\+?\d( *\d+)+/g);
Output:
["+17865 8658", "98765"]
Upvotes: 1