Page 1 of 1

Das Eingabefeld wird auf dem negativen Symbol (-) Eintrag gelöscht. Wie man negative/positive Zahlen mit 2 Dezimalgrenze

Posted: 03 Mar 2025, 21:56
by Anonymous
Eingangsfeld wird auf dem negativen Symbol (-) Eintrag gelöscht.

Code: Select all

$("#txt-Total").on("input", function() {
let value = $(this).val();
let regex = /^-?\d*\.?\d{0,2}$/;

if (regex.test(value)) {
// Valid input: allows negative sign, digits, and up to two decimal places
$(this).data('previousValue', value); // Store valid value
} else {
// Invalid input: restore to the last valid value
$(this).val($(this).data('previousValue') || '');
}
});< /code>