Thursday, 3 May 2012

paste only numbers in text box using javascript

   In this Example i am Describing , Paste only numbers or numeric in the text box..
here if we copying characters + numbers it will paste (display) only Numbers

Here is the Example

1)First Copy Any data:

2)Paste in second text box

3)final OUTPUT:

Text box onpaste :
onpaste="return paste(this);"


function paste(obj) {
            var totalCharacterCount = window.clipboardData.getData('Text');
            var strValidChars = "0123456789";
            var strChar;
            var FilteredChars = "";
            for (i = 0; i < totalCharacterCount.length; i++) {
                strChar = totalCharacterCount.charAt(i);
                if (strValidChars.indexOf(strChar) != -1) {
                    FilteredChars = FilteredChars + strChar;
            obj.value = FilteredChars;
            return false;


  1. I was spend my time in saerching in google

    thanks a lot

  2. This code works fine in Internet explorer,but its not working in chrome

  3. It is very good blog and useful for students and developer , Thanks for sharing

    Dot Net Online Training Bangalore