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)