I have been tasked with the impossible, maybe?
I have a table with telephone numbers. But they are manually entered, and very dirty.
Example:
0711112399
07 1111 3288
07 1111 4832 NIKKI
0711117929
0711113616X123
0
NULL
1300 111 782
.
(Numbers changed to protect the innocent. :))
I need to break these into
CountryCode
AreaCode
Number
Extension
So, 0711112399 would become
CountryCode = +61 (Because there is no code on this number)
AreaCode = 07
Number = 11112399
Extension = NULL
11113616X123 would be
Country +61
AreaCode = NULL
Number = 11113616
Extension = 123
Rules are:
Possible area codes:
02 03 04 07 08
Is this even possible?
For 07 1111 4832 NIKKI – I will remove Alpha Numerics, unless it’s an X between 2 numbers.
You can try this
See it here on Regexr. You can see the content of the groups while hovering over the blue highlighted matches.
It will put the country code in Group1, the area code in group 2, the number in group 3 and the extension in group 4. All parts are optional except the number. When a part is not found, the value of the group is not set, you have to put your default values then.
I see a problem for the country code. It is hardcoded here with 2 digits, but I know there are also countries with a 3 digit code. For the countries with a 1 digit code, I am not sure, could be that there is a leading 0 then. But I need this to know when the area code/the number is starting.