disable paste and buang sen at tebus
This commit is contained in:
@@ -310,7 +310,7 @@
|
|||||||
<span>DUIT PELANGGAN (RM)</span>
|
<span>DUIT PELANGGAN (RM)</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<input type="text" id="duitPelanggan" onkeyup="bayaranPelanggan(this)" placeholder="0.00" class="form-control"/>
|
<input type="text" id="duitPelanggan" onkeyup="bayaranPelanggan(this)" onpaste="return false;" ondrop="return false;" onkeypress="return validateFloatKeyPressDuitPelanggan(this,event);" placeholder="0.00" class="form-control"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group row" id="divbakiPelanggan">
|
<div class="form-group row" id="divbakiPelanggan">
|
||||||
@@ -3504,6 +3504,44 @@ function validateFloatKeyPress(el, evt) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validateFloatKeyPressDuitPelanggan(el, evt) {
|
||||||
|
|
||||||
|
var charCode = (evt.which) ? evt.which : event.keyCode;
|
||||||
|
var number = el.value;
|
||||||
|
let keypress = evt.key;
|
||||||
|
|
||||||
|
// Split the current value by dot to check the number of decimal places
|
||||||
|
var numberParts = number.split('.');
|
||||||
|
|
||||||
|
// Check if the pressed key is a valid character for a floating-point number
|
||||||
|
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if there is already a dot, and the pressed key is another dot
|
||||||
|
if (numberParts.length > 1 && charCode == 46) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the caret position in the input field
|
||||||
|
var caratPos = getSelectionStart(el);
|
||||||
|
|
||||||
|
// Get the position of the existing dot
|
||||||
|
var dotPos = el.value.indexOf(".");
|
||||||
|
|
||||||
|
// Check if the caret is after the existing dot, and there are more than 2 digits after the dot
|
||||||
|
if (caratPos > dotPos && dotPos > -1 && (numberParts[1] && numberParts[1].length > 1)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the last digit is not 5 or 0, disallow the input
|
||||||
|
if (numberParts[1] && numberParts[1].length === 1 && !['0', '5'].includes(keypress)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function getSelectionStart(o) {
|
function getSelectionStart(o) {
|
||||||
if (o.createTextRange) {
|
if (o.createTextRange) {
|
||||||
var r = document.selection.createRange().duplicate()
|
var r = document.selection.createRange().duplicate()
|
||||||
|
|||||||
Reference in New Issue
Block a user