I have custom string containing text and phone number. How I can extract this number?
Example text:
Lorem ipsum +44 12-45-243 dolor 00(49) 812 234 234
EDIT: Phone number can be of any given format.
I have custom string containing text and phone number. How I can extract this number?
Example text:
Lorem ipsum +44 12-45-243 dolor 00(49) 812 234 234
EDIT: Phone number can be of any given format.
Here is a thread about regex expresions on phone numbers:
A comprehensive regex for phone number validation
I believe it will be helpful for your task.
Here is one of the most upvoted regex for 7 to 10 digits:
^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$
Edit: Sorry, I meant to make it as a comment but I don't have the reputation yet.
Ok I found a solution.
I can use libphonenumber and findNumbers function.
first of all you could remove all the spaces, dashes and ... then just read the string and keep attached numbers in an array, then check if the number is valid with whatever your validation algorithm is. This will work but sure it is not efficient.