title: Only binary format input
body: <p>I have a small issue. I am creating my own small program that includes a Binary calculator. I have the calculator created, but what I want to do is limit the input of the user in the <code>jTextField</code> only to 1s and 0s. If that is not possible than when the user enters anything else besides 1s and 0s , the button that is used to convert (calculate) from binary to decimal to get automatically disabled when the user inputs anything else besides 1s and 0s.</p>
  
  <p>I have tried looking in other questions, but I don't think it is a duplicate. If it is, I apologize.</p>
  
  <p>Anyone any idea?</p>
  
  <p>EDIT:</p>
  
  <p>The code below is my Bin to Dec converter method used in the actionPerformed method of the button:</p>
  
  <pre><code>void BinToDec() {
          if (tfNumber.equals("")) {
              JOptionPane.showMessageDialog(null, "No values entered");
          }
          decList = new ArrayList&lt;Integer&gt;();
          try {
              int binary = Integer.parseInt(tfNumber.getText());
              if(binary &gt;= 0) {
                  int temp = binary;
                  do {
                      decList.add(temp % 10);
                      temp /= 10;
                  } while(temp &gt; 0);
                  w = 0;
                  x = 0;
                  sum = 0;
                  for(int i = 0; i &lt; decList.size(); i++) {
                      w = decList.get(i);
                      x = (int)Math.pow(2, i);
                      w = w * x;
                      sum = sum + w;  
                  }
                  result = Integer.toString(sum);
                  tfBin.setHorizontalAlignment(tfBin.CENTER);
                  tfBin.setText(result);
                  JOptionPane.showMessageDialog(null, "Decimal for the binary number " + tfNumber.getText() + " is: " + result, "Decimal representation of a Binary number", JOptionPane.INFORMATION_MESSAGE);
                  lblBin.setText(String.valueOf(result.replaceAll("[^\\dA-Za-z ]", "").trim()));
  
              } else {
                  JOptionPane.showMessageDialog(null, "You didn't enter a correct value! Please enter only a positive number", "Error - Incorrect Value", JOptionPane.ERROR_MESSAGE);
              }
          } catch(NumberFormatException ex) {
              JOptionPane.showMessageDialog(null, "You didn't enter a correct value! Please enter only a positive number", "Error - Incorrect Value", JOptionPane.ERROR_MESSAGE);
          }
      }   
  </code></pre>
  
  <p>EDIT 2: The same <code>JTextField</code> is used when a user enters a number and wants to convert it to Binary format, so the check must be performed in the above method </p>