Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<input type = "text" runat="server" id="Empid" Placeholder = "Employee id">


In run mode as follows

Employee id ( numbers only allowed)

for that how can i do please help me.

What I have tried:

how to make input tag numbes only allowed
Posted
Updated 1-Sep-16 19:37pm

this the code i had used long back was in my notes, not sure where i had got from to provide the reference and credit :). Try this.

F#
$(document).ready(function() {
    $("#Empid").keydown(function (e) {
        // Check for backspace, delete, tab, escape, enter, do not restrict that
        if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
             // Allow: Ctrl+A
            (e.keyCode == 65 && e.ctrlKey === true) ||
             // Allow: Ctrl+C
            (e.keyCode == 67 && e.ctrlKey === true) ||
             // Allow: Ctrl+X
            (e.keyCode == 88 && e.ctrlKey === true) ||
             // Allow: home, end, left, right
            (e.keyCode >= 35 && e.keyCode <= 39)) {
                 // let it happen, don't do anything
                 return;
        }
        // Restrict other special keys..
        if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
            e.preventDefault();
        }
    });
});


Hope this helps..

Hussain
Happy Coding.
 
Share this answer
 
v2
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900