private boolean isValid(final String string, final int replaced) {
    if (((getFormattedTextField().getText().length() - replaced) + string.length()) > maxSize) {
      invalidEdit();
      return false;
    }

    for (int i = 0; i < string.length(); i++) {
      final char ch = string.charAt(i);

      if (Character.digit(ch, 16) == -1) {
        invalidEdit();
        return false;
      }
    }

    return true;
  }
Hex formatter that can be used to validate input for hexadecimal text fields. Taken from
http://forum.java.sun.com/thread.jspa?threadID=436233&messageID=3169976

<p>Slightly modified.
java/zylib/src/main/java/com/google/security/zynamics/zylib/gui/CHexFormatter.java