سؤال

I have a phone number that can appear in different formats. I need to match that number with a model number.

Incoming call is the number from which the call is coming and the other numbers are the formats in which the numbers are saved in our phone table.

So how can I split the string so that I could get/verify meaningful output?

   public class Trial {

    public static void main(String[] args) {
        String incomingcall,number1,number2,number3,newincoming,new1 = null;
        incomingcall="+919045308261";
        number1="9045308261";
        number2="09045308261";
        number3= "+91 90 45 308261";

        //int i= incomingcall.length();
        newincoming=incomingcall.replace("+91", "000");
        System.out.println(newincoming);
        if(number1.length()<=10){
        new1 =  ("000"+number1);
            System.out.println(new1);
        }

        if(newincoming.equals(new1)){
            System.out.println("Numbers matched");
        }


    }

}
هل كانت مفيدة؟

المحلول

Let's make it an official answer shall we?

Here is a phone number parser/validator put out by Google code.google.com/p/libphonenumber

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top