Tuesday, 8 February 2022

How to extract plain number from a Phone number?

We have different format of phone number, we may need to extracts just plain number from the phone number.
Here is the utility method we can add.

public static String normalizePhone(String initialString){
        String resultNumber;
        if(initialString != null){
            resultNumber = initialString.replaceAll('[^0-9.]', '');
        }
        return resultNumber;
    }

No comments: