Hi All,
I have an input textbox the user enters numbers into. I only want the user to enter positive numbers. I wrote this function that checks the contents of the control - searching for letters or "-" negitive sign. It picks up the letters fine. But does not pick up the "-" sign. My code is below:
Being called from the input textbox onBlur method.
Called from the ckMinAmount function.
Any help would be most appreciated.
TIA,
Tim
I have an input textbox the user enters numbers into. I only want the user to enter positive numbers. I wrote this function that checks the contents of the control - searching for letters or "-" negitive sign. It picks up the letters fine. But does not pick up the "-" sign. My code is below:
Being called from the input textbox onBlur method.
Code:
function chkMinAmount(frmName) {
var tempNum = document.forms[frmName].fromAmt.value;
if (tempNum.length != 0) {
if (amountCheck(frmName,tempNum)) {
alert("Enter positive numbers only.");
document.forms[frmName].fromAmt.value = "";
document.forms[frmName].fromAmt.focus();
}else {
var newValue = formatNumber(tempNum);
document.forms[frmName].fromAmt.value = newValue;
document.forms[frmName].amountRange.checked = true;
}
}
}
Called from the ckMinAmount function.
Code:
function amountCheck(frmName,amountIn) {
var amt = amountIn;
if (!amt) return false;
var iChars = "-AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
for (var i = 0; i < amt.length; i++) {
if (iChars.indexOf(amt.charAt(i)) == -1)
return false;
}
return true;
}
Any help would be most appreciated.
TIA,
Tim