I am using the following code:
Pattern p = Pattern.compile("^\\+?[1-9]\\d{1,14}$");
stringNumber=stringNumber.replace(" ","");
Matcher m = p.matcher(stringNumber);
if (!m.matches())
{
[...]
}
And the template, which should correctly determine the numbers in the E.164 format, does not work, as I think, it should, because it gives a valid E.164 phone number, a number in the format XXXXXXXXX, which is X all digits from 0 to 9. And how much I look at the template, I can’t understand why.
The stricter pattern "^ \ +? \ D {10,14} $" really works because it detects that the number XXXXXXXXX is not in the format.
Perhaps the last template is enough for my applications, but I would like to use the first (one that could determine that the phone number is in E.164 format in each case) to get a wider range of possibilities, even if these possibilities are rare.
What can cause unexpected behavior with the first pattern?