Regex for formatting the mobile numbers in Java to standard format [duplicate]

In the DB, I have a table people, in that I have a column named Mobile.
So for this column I need to format the mobile number as 0405506665.

The current format I have in database is

  1. 0450554345 – space before mobile number
    2)(07) 4624 2400
    3)+61405545454
    4)0433 369 993
    5)406774148
    6)0466375780 T or P 781
    7)±447590 674 599
    8)ا
    9)03 5986 5700
    10)0431-130-633
    11)?0432196200
    12)0433 369 9933

There are total 6-7 lakhs contacts including the correct format, can anyone suggest the best way to do this?

I am trying to write a regex in Java, but unable to find any regex which will support all these requirements

  • So… you want to get rid of anything that is not a digit? If so, just replace \D with nothing.

    – 

  • yes plus remove spaces and the one in +61 replace to 0 and remove special characters, and remove – and brackets too

    – 




  • Then replace +61 with 0, and after that remove all non-digit characters. Spaces, special characters, dashes and brackets all have non-digitness in common.

    – 

  • How will the regex look for it?

    – 

  • s.replaceAll("\\+61", "0").replaceAll("\D", "")

    – 




Leave a Comment