how can I do a regex that follow the exact format below? With spaces, signs, brackets, everything?
+44 (0)20 1234 5678
These would also need to work:
+44 (0)79 1234 567
+44 (0)79 1234 5678
+44 (0)79 1234 56789
+44 (0)79 1234 567810
how can I do a regex that follow the exact format below? With spaces, signs, brackets, everything?
+44 (0)20 1234 5678
These would also need to work:
+44 (0)79 1234 567
+44 (0)79 1234 5678
+44 (0)79 1234 56789
+44 (0)79 1234 567810
I give you some suggestion that will make you able to solve the problem. Then you can try to build your own regex with RegExr.
+
, (
, and )
have special meaning in a regex, so they need to be escaped with \+
, \(
and \)
.
A digit can be matched with [0-9]
or simply \d
.
If you want to match x
twice, you can use the syntax x{2}
, if a number of times between 2
and 50
you can use x{2,50}
.
A single space can be matched by .
Easy enough?