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);"

Script:
-------

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;
        }





Related Posts:

  • Different Culture Names CULTURE ||SPEC.CULTURE||ENGLISH NAME af af-ZA Afrikaans af-ZA af-ZA Afrikaans (South Africa) ar ar-SA Arabic ar-AE ar-AE Arabic (U.A.E.) ar-BH ar-BH Arabic … Read More
  • Word document in iframe This is screen shot for iframe.Here In the below Screenshot iframe viewing the word document in the form of html. so i am giving html to the Iframe src. Iframe can view excel,csv,pdf,text file… Read More
  • Culture info in RadDateTime Picker In this example we can give culture info for localization in RadDatetimePicker. for this below example u can get different localizations according to their country. it is one of the property in RadDateTimePicke… Read More
  • Word Documents and Excel Documents in IFRAME In this below example we are converting word OR excel document to HTML. In this case we are converting and giving converted HTML file as ""src"" to ""iframe"". Step By Step Procedure : 1)First step is create one… Read More
  • Replace characters in javascript In server side we have "Replace" method to replace the characters in a string but on javascript replace method will be not useful in certain cases instead of that we can do for loop to replace the particular characters and g… Read More

4 comments:

  1. I was spend my time in saerching in google

    thanks a lot

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

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



    Dot Net Online Training Bangalore

    ReplyDelete