How to validate phone number(US format) in Java?

Posted by Maxood on Stack Overflow See other posts from Stack Overflow or by Maxood
Published on 2010-04-21T15:59:17Z Indexed on 2010/04/21 16:03 UTC
Read the original article Hit count: 126

Filed under:

I just want to know where am i wrong here:

import java.io.*;


    class Tokens{   
            public static void main(String[] args)
            {
               //String[] result = "this is a test".split("");

                String[] result = "4543 6546 6556".split("");
                boolean flag= true;         

                String num[] = {"0","1","2","3","4","5","6","7","8","9"};
                String specialChars[] = {"-","@","#","*"," "};


                for (int x=1; x<result.length; x++)
                {   
                    for (int y=0; y<num.length; y++)
                    {
                        if ((result[x].equals(num[y])))
                        {
                            flag = false;
                            continue;

                        }
                        else
                        {
                            flag = true;
                        }


                        if (flag == true)
                        break;

                    }   

                if (flag == false)
                break;

                }           

                System.out.println(flag);

            }

    }

© Stack Overflow or respective owner

Related posts about java