Start a new topic

To add missing zero in the beginning of phone numbers

We have inconsistency of format for phone numbers we are importing. Also some numbers have leading zero, others doesn't.

I already have Reg EX which applies UK formatting to the numbers we are importing.

As an example, Reg Ex for London based numbers:

-Blank-RegEx -> Space (to remove all spaces in original phone number)

$1 $2 $3 Reg Ex -> ^(020)(\d{4})(\d{4})$

But looks like i need additional layer to add missing zeros so this Reg Ex would work on all importing phone numbers. Because all my RegEx are based on either beginning of phone number which has leading zero or amount numbers in UK phone numbers, therefore numbers without leading zero are not getting formatted.

Resolved: I did managed to amend my Reg Ex, now its adding leading zero where it's missing.

Hello Vita, could you add your amended Reg Ex to add leading zero where missing please.

Thank you

Of course, here is my completed dictionary to format UK landline.

To format UK landline numbers:

1) Blank-RegEx -> Space



To removes spaces and 44 in UK landline, make numbers in same format before applying other rules. We dont get 044 format, but can be added as another layer using ^044(?=.*) instead

2) 0$& -> ^\d{10}$ 

To add missing 0 if number of digits are less than standard 11

3) $1 $2 $3 -> ^(020)(\d{4})(\d{4})$




To separate number with spaces according standards. I covered formats of biggest cities like London, but this part can be extended.

4) $1 $2 -> ^(\d{5})(\d{6})$

If format is not recognised in 3) than number gets divided in slots xxxxx xxxxxx.

I have been using for quite some times, works as expected. Only exception if phone provided already has some manual error and inconsistency.

So from that 44 2084849595 we are getting 020 8484 9595 as result.

Mobile formatting i made in similar way, just skipping 3) step.

Hope it helps!


Login or Signup to post a comment