Stamps with Java Dialog

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Nimrod_189
User
Posts: 81
Joined: Wed Sep 23, 2009 8:39 am

Stamps with Java Dialog

Post by Nimrod_189 »

Hi everyone,

Does anyone know of a way in which I can replace the text entered in a text box within an Java-Dialog with a different text?

The idea is that I want to enter a date in a simplified format (e.g. 150826) and, when I leave the text box, this should be replaced with a proper date (15.08.2026). I already have the function for this, but I’m missing the option to replace the text.

Many thanks.

@Nimord_189

Code: Select all


app.alert(parseDate("210670"));
app.alert(parseDate("21,06,70"));
app.alert(parseDate("21/06/70"));
app.alert(parseDate("21.06.70"));
app.alert(parseDate("21-06-70"));


function parseDate(input) {
    // Alles außer Zahlen entfernen
    const numbers = input.replace(/\D/g, "");

    let day, month, year;

    if (numbers.length === 6) {
        // ddMMyy
        day = numbers.substring(0, 2);
        month = numbers.substring(2, 4);
        year = numbers.substring(4, 6);

        // Zweistelliges Jahr interpretieren
        year = Number(year) >= 50
            ? 1900 + Number(year)
            : 2000 + Number(year);

    } else if (numbers.length === 8) {
        // ddMMyyyy
        day = numbers.substring(0, 2);
        month = numbers.substring(2, 4);
        year = numbers.substring(4, 8);

    } else {
        return null; // Ungültiges Format
    }

    const date = new Date(
        Number(year),
        Number(month) - 1,
        Number(day)
    );

    // Prüfen, ob das Datum tatsächlich gültig ist
    if (
        date.getFullYear() !== Number(year) ||
        date.getMonth() !== Number(month) - 1 ||
        date.getDate() !== Number(day)
    ) {
        return null;
    }

    return util.printd("dd.mm.yyyy",date);
}


Translated with DeepL.com (free version)