For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Friday, November 15, 2013

Accept only numeric character with BACKSPACE and TAB button facility

Accept only numeric character with BACKSPACE and TAB button facility.

When you enter some numeric value in age or amount like textbox then you not need to enter any other character. there are lot of script available in the internet about this. but they don't support BACKSPACE and TAB button facility. here are listed below code will support BACKSPACE and TAB button facility.

Enter Roll Number only in numeric charactes:
<input type="text" id="roll" name="roll" onkeypress="checkNumeric(event);" />
<script>
function checkNumeric(e) {
    if (window.event) { // IE
        if(e.keyCode==13 || e.keyCode==0 || e.keyCode==8)  {
            event.returnValue = true;
            return true;
        }
        if ((e.keyCode < 48 || e.keyCode > 57) & e.keyCode != 8) {
            event.returnValue = false;
            return false;
        }
    } else { // FF
           if(e.which==13 || e.which==0 || e.which==8)  {
            return true;
        }
        if ((e.which < 48 || e.which > 57) & e.which != 8) {
            e.preventDefault();
            return false;
        }
    }
}  
</script>

Share:

0 comments:

Post a Comment

Add Dependent Scripts

   here is the code that allow to add dependent script :         <script>         const addDependentScripts = async function( scriptsT...

Ads Inside Post

Powered by Blogger.

Arsip