I am trying to normalise UK telephone numbers to international format.
The following strings should resolve to: +447834012345
- 07834012345
- +447834012345
- +4407834012345
- +44 (0) 7834 012345
- +44 0 7834 012345
- 004407834012345
- 0044 (0) 7834012345
- 00 44 0 7834012345
So far, I have got this:
"+44" + mobile.replaceAll("[^0-9]0*(44)?0*", "")
This doesn't quite cut it, as I am having problems with leading 0's etc; see table below. I'd like to try and refrain from using the global flag if possible.
Mobile | Normalised |
--------------------+--------------------+------
07834012345 | +4407834012345 | FAIL
+447834012345 | +447834012345 | PASS
+4407834012345 | +447834012345 | PASS
+44 (0) 7834 012345 | +44783412345 | FAIL
+44 0 7834 012345 | +44783412345 | FAIL
004407834012345 | +44004407834012345 | FAIL
0044 (0) 7834012345 | +4400447834012345 | FAIL
00 44 0 7834012345 | +44007834012345 | FAIL
+4407834004445 | +447834004445 | PASS
Thanks