@Override
    public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
        if (str == null){
            return;
        }
        boolean validate = false;
        switch (mode) {
            case DocumentLimit.DIGIT_AND_LETTER_ONLY:
                if (Character.isLetterOrDigit(str.charAt(0))){
                    validate = true;
                }
                break;
            case DocumentLimit.ONLY_DIGIT:
                if (Character.isDigit(str.charAt(0))){
                    validate = true;
                }
                break;
            case DocumentLimit.ONLY_LETTER:
                if (Character.isLetter(str.charAt(0))){
                    validate = true;
                }
                break;
            case DocumentLimit.NONE:
                validate = true;
                break;
        }
        if (validate && getLength() + str.length() <= this.limit){
            super.insertString(offs, str, a);
        }
    }