Thursday, 15 March 2012

Allow only numbers in textbox using javascript

Use the following code:

function AllowNumsOnly(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        document.getElementById('spnError').innerHTML = 'Allows only numbers';
        return false;
    }
    else {
        document.getElementById('spnError').innerHTML = '';
        return true;
    }
}
<style>
    #spnError {color:Red;font-size:11px;}
</style>
<asp:TextBox ID="txt_Qty" runat="server" onkeypress="return AllowNumsOnly(event);"></asp:TextBox><span id="spnError"></span>

Tag: Allow only numbers in textbox using javascript,allow numbers only onkeypress

1 comment:

Parsing JSON w/ @ symbol in it

To read the json response like bellow @ concatenated with attribute                             '{ "@id": 1001, "@name&q...