I have a phone number formatted like this.+251-911-123456.
How could I create a regex that matches the given format.
I was trying to do it with the bellow given expression but it is not a success.
^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$
I have a phone number formatted like this.+251-911-123456.
How could I create a regex that matches the given format.
I was trying to do it with the bellow given expression but it is not a success.
^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$
You may use
/^\+\d{3}-\d{3}-\d{6}$/
Details
^
- start of string \+
- a +
symbol\d{3}
- three digits-
- a hyphen\d{3}
- three digits-
- a hyphen\d{6}
- six digits$
- end of string.See the regex demo and the Regulex graph: