title: Checking format errors in a String using Java
body: <p>So this is a part of a dice rolling program I have been plugging away at for the past few days... Language parsing isn't my strong suit, so I thought I would ask for some help.</p>
  
  <p>The input buttons are <code>[0]</code>, <code>[1]</code>, <code>[2]</code>, <code>[3]</code>, <code>[4]</code>, <code>[5]</code>, <code>[6]</code>, <code>[7]</code>, <code>[8]</code>, <code>[9]</code>, <code>[0]</code>, <code>[d4]</code>, <code>[d6]</code>, <code>[d8]</code>, <code>[d10]</code>, <code>[d12]</code>, <code>[d20]</code>, and <code>[ROLL]</code>; <code>[ROLL]</code> uses a separate handler from the others. <code>codeStr</code> is a String and <code>etCalc</code> is a EditText.</p>
  
  <p>The cases I need to handle especially are in my TODO tags, namely when extra numbers come after the [dn] button press currently it will roll a larger number die instead of disallowing the action from being performed which was my intent. And <code>[dn][dn]</code>, where two die rolls come after each other implying dice multiplication which my program isn't set to handle.</p>
  
  <pre><code>public void calcButtonClick(View view) {
      Button b = (Button) view;
      String buttonText = b.getText().toString();
  
      // TODO: Case: dn[extraneous numbers]
      // TODO: Case: d[n]d[n]
      codeStr = codeStr + buttonText;
      etCalc.setText(codeStr);
  }
  </code></pre>