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

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

Post 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>


Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post