title: How to make a condition of two fields?
body: <p>Good afternoon, I need to add several conditions to validate two fields in the current code.</p>
  <ol>
  <li>The Min field must not exceed the Max field. Min &lt;Max / 5000
  &lt;4000 prohibited when entering.</li>
  <li>The Max field must not be less than the Min field. Max &lt;Min / 4000 &lt;5000 prohibited when entering.</li>
  <li>The Min field should not exceed the interval from the Max field, 500 units less can be entered.
  For instance:
  Min 4500 and Max 5000, 4400/5000, 4250/5000, 4501/5000 are prohibited to enter and above.</li>
  <li>The Min and Max fields must not be equal. Min = Max is prohibited when entering.</li>
  </ol>
  <p><a href="https://i.stack.imgur.com/xd4v6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xd4v6.png" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/3QQ0N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3QQ0N.png" alt="enter image description here" /></a><a href="https://i.stack.imgur.com/qx8Ec.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qx8Ec.png" alt="enter image description here" /></a></p>
  <p>code:</p>
  <pre><code>import controlP5.*;
  
  ControlP5 cp5;
  Textfield O;
  Textfield OO;
  
  void setup() {
    size(700, 400);
  
    PFont font = createFont(&quot;arial&quot;, 18);
  
    cp5 = new ControlP5(this);
  
    O = cp5.addTextfield(&quot;MIN&quot;)
      .setPosition(20, 100)
      .setSize(200, 40);
    O.setInputFilter(ControlP5.INTEGER)
      .setFont(font)
      .setColor(color(255, 0, 0));
  
    OO = cp5.addTextfield(&quot;MAX&quot;)
      .setPosition(20, 170)
      .setSize(200, 40);
    OO.setInputFilter(ControlP5.INTEGER)
      .setFont(font);
  
    textFont(font);
  }
  
  void draw() {
    if (keyPressed &amp;&amp; OO.isFocus()) {
      float n;
      try {
        n = Float.parseFloat(OO.getText().replace(',', '.'));
        if (!(n &gt;= 1 &amp;&amp; n &lt;= 12000)) {
          throw new NumberFormatException(); // throw to catch below
        }
      } 
      catch (Exception e2) {
        String t;
        if (OO.getText().length() &gt; 1) {
          t = OO.getText().substring(0, OO.getText().length() - 1);
        } else {
          t = &quot;&quot;;
        }
        OO.setText(t);
      }
    }
    if (keyPressed &amp;&amp; O.isFocus()) {
      float n;
      try {
        n = Float.parseFloat(O.getText().replace(',', '.'));
        if (!(n &gt;= 1 &amp;&amp; n &lt;= 11500)) {
          throw new NumberFormatException(); // throw to catch below
        }
      } 
      catch (Exception e2) {
        String t;
        if (O.getText().length() &gt; 1) {
          t = O.getText().substring(0, O.getText().length() - 1);
        } else {
          t = &quot;&quot;;
        }
        O.setText(t);
      }
    }
    background(0);
    fill(255);
  }
  </code></pre>