title: How do I validate for leading zeros for an int?
body: <p>I'm trying to validate input so that the user is only allowed to input an int that has 9 digits. My current code takes care of leading zeros, any input that is more than 9 digits but not if it's less than 9 digits.</p>
  
  <p>For example, it should not allow the user to input the int 123.</p>
  
  <p>The code below validate for number input if the digit is longer than 9, but it does not take into account of the digits being less than 9.</p>
  
  <pre><code>public void setSSN(int sSN) {
  
      String temp = "";
  
      do {
          temp = String.format ("%09d", sSN);
          if(temp.length() != 9) {
              sSN = Methods.getInt("Enter an 9 digits");
          }
      }while(temp.length() != 9);
  
      temp = temp.substring(0,3) + "-" + temp.substring(3,5) + "-" +temp.substring(5,9);
      JOptionPane.showMessageDialog(null, temp);
      SSN = sSN;
  }
  </code></pre>
  
  <p>If the user input in int less than 9 digits. It would fill in the rest of the slots and make it 9 digits due to String.format (I only include this so it would work for leading zeros). I'm not sure how to get around that leading zeros as well as making sure the input is exactly 9 digits.</p>
  
  <p>TEST CASES:</p>
  
  <p>Input: 123456789
  Output: 123-45-6789</p>
  
  <p>Input: 001234567
  Output: 001-23-4567</p>
  
  <p>//Below is what I don't want</p>
  
  <p>Input: 12<br>
  Output: 000-00-0012</p>