I’m trying to create a regex for a phone number validation. The pattern should work like that: if the user writes the prefix (with the plus symbol optional), then the phone number must follow with 4 to 14 numbers. Otherwise, when the prefix is not given, the user has to write from 4 to 14 numbers only.
The regex I wrote is that:
^([+]?[0-9]{1,3})([0-9]{4,14})$|^([0-9]{4,14})$
I’ve tested the regex with these strings:
3333333333 –> works
+393333333333 –> works
+39333 –> works but it shouldn’t. I expected to have at least four numbers after the prefix
What am I missing?