I've seen multiple questions/answers regarding phone number authentication, which is great, but all of them only seen to work IF the string is strictly a phone number. In my case, we might have receive a string like this:
"Okay, I've got your number as 313-123-1234. Now lets..."
The formatting of the phone number can vary as well, so I think it would be better if the regex could handle "any sequence of 10 numbers, ignoring ( ) - ."
I've tried a few different things, including:
"^((\\+\\d{1,2}|1)[\\s.-]?)?\\(?[2-9](?!11)\\d{2}\\)?[\\s.-]?\\d{3}[\\s.-]?\\d{4}$"
and
"/[0-9]{10}\\b/"
Among others, which, again, seen to work if it's the phone number by itself, but when I call:myStrig.matches(myRegex);
on the full string, it always returns false.
With that being said, is there either a native solution, such as PhoneNumberUtils.isGlobalPhoneNumber(phoneNumber)
that would work with the example phrase mentioned above, or what is a regex that would actually work in this case?
Thanks!