public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {

            if (str == null) {
                return;
            }
            char[] upper = str.toCharArray();
            String filtered = "";
            for (int i = 0; i < upper.length; i++) {
                if (Character.isDigit(Character.codePointAt(upper, i))) {
                    filtered += upper[i];
                } else {
                    Toolkit.getDefaultToolkit().beep();
                }
            }
            super.insertString(offs, filtered, a);
        }