Java - Program that checks if the user's serial code format is valid or not
<p>I'm trying to create program that will ask the user to enter serial numbers in a specific format and the program will verify if the codes are valid or not.</p>

<p>The format should be 2 numbers, followed by a dash, 4 numbers, a dot, then 4 numbers and 2 letters (note: letters accepted are only a,b,c). </p>

<p>Example of valid format:</p>

<pre><code>31-0001.2341ac    
00-9999.0001cb
</code></pre>

<p>If the length of the string is longer/shorter than the format (14 characters total length) it should display invalid. Same thing, if other characters were used it will also say invalid.</p>

<p>This is the code that I have done so far. Im not sure how I can achieve the exact specified format. Hopefully someone can help..</p>

<pre><code>import java.util.Scanner;

    public class SerialCheck{
        public static void main (String[] args){

        Scanner sc = new Scanner(System.in);

        System.out.print("How many serial numbers would you like to check: ");
        int length = sc.nextInt();
        int valid = 0;

        String[] sSerials = new String[length];

        for (int nCtr = 0; nCtr &lt; length; nCtr++){
            System.out.print ("Enter Serial " + (nCtr+1) + ": ");
            sSerials[nCtr] = sc.next();
        }

        System.out.println();
        System.out.println("The following were added: ");
            for(int nCtr = 0; nCtr &lt; length; nCtr++){
            System.out.println(sSerials[nCtr]);
        }

        System.out.println();
            for(int nCtr = 0; nCtr &lt; length; nCtr++){
                for (int x = 0; x &lt; sSerials[nCtr].length(); x++){
                    char c = sSerials[nCtr].charAt(x);

                if((sSerials[nCtr].charAt(x)!='a') || 
                   (sSerials[nCtr].charAt(x)!='b') || 
                   (sSerials[nCtr].charAt(x)!='c') ||
                   (sSerials[nCtr].charAt(x)!='-') ||
                   (sSerials[nCtr].charAt(x)!='.')){
                    valid--;
                } 
                else{
                    valid++;
                }
            }
            if (valid &lt; 0 &amp;&amp; sSerials[nCtr].length() != 14){
                System.out.println("The address is invalid.");
            }
            else{
                System.out.println("The address is valid.");
            }

        }

    }
}
</code></pre>