I have a textbox where user enters interest rate. The valid value format of this input are as follows, only integer or decimal. I have used asp.net validator for this as:
<asp:RegularExpressionValidator ID="revtxtInterestRate" runat="server" ErrorMessage="Put correct interest rate" Display="Dynamic"
ControlToValidate="txtInterestRate"
ValidationExpression="^[0-9]\d*(\.\d+)?$"
ValidationGroup="submitValidate"
ForeColor="Red"></asp:RegularExpressionValidator>
I want to use onkeypress
event for this textbox to avoid enter alphabets, special characters, spaces, and two dots. How can I do that ?
I have onkeypress
function for number format but do not have idea to modify this function to use for the above requirement.
function numberOnly(evt) {
var charCode = (evt.which) ? evt.which : window.event.keyCode;
if (charCode <= 13) {
return true;
}
else {
var keyChar = String.fromCharCode(charCode);
var re = /[0-9]/
return re.test(keyChar);
}
}