I'm attempting to trigger a pop-up warning to the user when any characters that is not an integer or decimal point is entered.
HTML:
<asp:TextBox ID="TextBox1" runat="server" onkeyup="checkTB(this.value)"/>
JS:
function checkTB(val) {
var allowedString = new RegExp("^[\d.]+$");//only allow integers & decimal places
if (allowedString.test(val) == false) {
alert("FORBIDDEN"+val);
}
}
However the alert triggers regardless of whether the RegExp test is true or false as it triggers regarless of whether I enter integers or alphabets. Why is this happening?