title: Validate a String (PPS number)
body: <p>Okay, I'm trying to validate a String (in this case the PPS number). I can't seem to get it to work properly.</p>
  
  <p>Here's the question: </p>
  
  <blockquote>
    <p>Each Irish citizen is allocated a PPS number once they reach the age
    of 18 that is unique to them and used for taxation purposes. A valid
    PPS number will have exactly 8 or 9 characters in total. It will begin
    with exactly 7 digits and end with one or two uppercase letters. So,
    for example, 1234567A would be considered a valid PPS number, as would
    7863456RT, but 6478TY*%&amp; and 8768086b would both be considered invalid
    PPS numbers.</p>
  </blockquote>
  
  <pre><code>package Assess2013Two;
  import java.util.Scanner;
  public class Group3Solution {
      public static void main(String[] args)
      {
          int index = 0;
          char ch;
          Scanner input = new Scanner(System.in);
  
          System.out.print("Please enter your PPS number: ");
          String ppsNumber = input.nextLine();
  
          if(ppsNumber.length() &gt;= 8 &amp;&amp; ppsNumber.length() &lt;= 9){
              if(ppsNumber.charAt(7) &gt;= 'A' &amp;&amp; ppsNumber.charAt(7) &lt;= 'Z' &amp;&amp; ppsNumber.charAt(8) &gt;= 'A' &amp;&amp; ppsNumber.charAt(8) &lt;= 'Z')
              {
                  if(ppsNumber.length() == 8) {
                      ch = ppsNumber.charAt(index);
                      while(index &lt; ppsNumber.length() &amp;&amp; ch &gt;= '0' &amp;&amp; ch &lt;= '9'){
                          index++;
                          if(index &lt; ppsNumber.length())
                              ch = ppsNumber.charAt(index);
                      }
                      if(index == ppsNumber.length())
                          System.out.println("You entered a valid PPS number.");
                      else
                          System.out.println("Invalid PPS number!! At least one of the first 7 characters were not digits.");
                  }else {
                      ch = ppsNumber.charAt(index);
                      while(index &lt; ppsNumber.length()-2 &amp;&amp; ch &gt;= '0' &amp;&amp; ch &lt;= '9'){
                          index++;
                          if(index&lt;ppsNumber.length()-2)
                              ch = ppsNumber.charAt(index);
                      }
                      if(index == ppsNumber.length()-2)
                          System.out.println("You entered a valid PPS number.");
                      else
                          System.out.println("Invalid PPS number!! At least one of the first 7 characters were not digits.");
                  }
  
  
              }else
                  System.out.println("Invalid PPS number!! The second-last or last, or both, were not uppercase letters");
          }else
              System.out.println("Invalid PPS number!! It must contain at least 8 to 9 characters.");
  
          input.close();
      }
  }
  </code></pre>