I'm trying to use the following code asking a user to enter a number and if it has a decimal then an error message.
vNumSamples = Number(validateNumSamples);
isWhole_re = Number(/^\s*\d+\s*$/);
if (isNaN(vNumSamples)) {
app.alert("Invalid \"Number of Samples\" value. It must be a number.");
return false;
}
if (vNumSamples<=0 || vNumSamples>12) {
app.alert("Invalid \"Number of Samples\" value. It must be between 1 and 12.");
return false;
}
if (isWhole_re != -1) {
app.alert("Invalid \"Number of Samples\" value. It must be a whole number (digits only)");
return false;
}
The problem I'm getting is that any number entered results in the error message:
Invalid Number of Samples value. It must be a whole number (digits only)
Is isWhole_re = Number(/^\s*\d+\s*$/); the correct code to check for whole numbers only?