public void caretUpdate(CaretEvent event) {
        String text = getText().trim();
        String emptyMask = maskPattern.replace('#', placeholder);

        if (text.length() == 0 || text.equals(emptyMask)) {
            setForeground(Color.BLACK);
            return;
        }

        try {
            Date date = dateFormatter.parse(getText());
            if (dateUtil.checkDate(date)) {
                setForeground(darkGreen);
            } else {
                setForeground(Color.RED);
            }
        } catch (Exception e) {
            setForeground(Color.RED);
        }
    }