Validate value < 0 and 2 decimal places for input berat permata

This commit is contained in:
amirhassan
2024-02-19 12:19:54 +08:00
parent 61861b836e
commit 4e0731a9c6
2 changed files with 115 additions and 1 deletions
+58 -1
View File
@@ -1031,6 +1031,19 @@
});
function validateBatuPermata(permata, berat) {
function countDecimalPlaces(value) {
const match = value.match(/(?:\.(\d+))?$/);
if (!match || !match[1]) {
return 0;
}
return match[1].length;
}
function validateInput(inputValue) {
const decimalPlaces = countDecimalPlaces(inputValue);
return decimalPlaces <= 2;
}
if(permata != '') {
if(berat == '') {
$("#tambah_marhun").prop('disabled', false);
@@ -1052,7 +1065,27 @@
});
event.preventDefault();
return false;
} else {
} else if(berat <= 0) {
$("#tambah_marhun").prop('disabled', false);
$("#terima_marhun").prop('disabled', false);
Swal.fire({
icon: 'error',
title: 'Amaran!',
text: 'Nilai berat permata mesti lebih besar daripada ' + berat,
});
event.preventDefault();
return false;
} else if(!validateInput(berat)) {
$("#tambah_marhun").prop('disabled', false);
$("#terima_marhun").prop('disabled', false);
Swal.fire({
icon: 'error',
title: 'Amaran!',
text: 'Hanya 2 titik perpuluhan dibenarkan untuk berat batu permata'
});
event.preventDefault();
return false;
}else {
return true;
}
} else if(berat != '') {
@@ -1068,6 +1101,30 @@
return false;
}
if(berat <= 0) {
$("#tambah_marhun").prop('disabled', false);
$("#terima_marhun").prop('disabled', false);
Swal.fire({
icon: 'error',
title: 'Amaran!',
text: 'Nilai berat permata ' + berat + ' tidak dibenarkan'
});
event.preventDefault();
return false;
}
if(!validateInput(berat)) {
$("#tambah_marhun").prop('disabled', false);
$("#terima_marhun").prop('disabled', false);
Swal.fire({
icon: 'error',
title: 'Amaran!',
text: 'Hanya 2 titik perpuluhan dibenarkan untuk berat batu permata'
});
event.preventDefault();
return false;
}
if(permata == '') {
$("#tambah_marhun").prop('disabled', false);
$("#terima_marhun").prop('disabled', false);
@@ -850,6 +850,19 @@
});
function validateBatuPermata(permata, berat) {
function countDecimalPlaces(value) {
const match = value.match(/(?:\.(\d+))?$/);
if (!match || !match[1]) {
return 0;
}
return match[1].length;
}
function validateInput(inputValue) {
const decimalPlaces = countDecimalPlaces(inputValue);
return decimalPlaces <= 2;
}
if(permata != '') {
if(berat == '') {
$("#tambah_marhun").prop('disabled', false);
@@ -871,6 +884,26 @@
});
event.preventDefault();
return false;
} else if(berat <= 0) {
$("#tambah_marhun").prop('disabled', false);
$("#terima_marhun").prop('disabled', false);
Swal.fire({
icon: 'error',
title: 'Amaran!',
text: 'Nilai berat permata mesti lebih besar daripada ' + berat,
});
event.preventDefault();
return false;
} else if(!validateInput(berat)) {
$("#tambah_marhun").prop('disabled', false);
$("#terima_marhun").prop('disabled', false);
Swal.fire({
icon: 'error',
title: 'Amaran!',
text: 'Hanya 2 titik perpuluhan dibenarkan untuk berat batu permata'
});
event.preventDefault();
return false;
} else {
return true;
}
@@ -887,6 +920,30 @@
return false;
}
if(berat <= 0) {
$("#tambah_marhun").prop('disabled', false);
$("#terima_marhun").prop('disabled', false);
Swal.fire({
icon: 'error',
title: 'Amaran!',
text: 'Nilai berat permata mesti lebih besar daripada ' + berat,
});
event.preventDefault();
return false;
}
if(!validateInput(berat)) {
$("#tambah_marhun").prop('disabled', false);
$("#terima_marhun").prop('disabled', false);
Swal.fire({
icon: 'error',
title: 'Amaran!',
text: 'Hanya 2 titik perpuluhan dibenarkan untuk berat batu permata'
});
event.preventDefault();
return false;
}
if(permata == '') {
$("#tambah_marhun").prop('disabled', false);
$("#terima_marhun").prop('disabled', false);