简体   繁体   English

电话号码解析和验证

[英]Phone number parsing and validation

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 这是Google code.google.com/p/libphonenumber推出的电话号码解析器/验证器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM