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:

  • Convert date format in javascript     Here in this example i am going to explain how to convert date into another format in javascript. Example : Here in this today's date will be obtained in the variable dt in system format and o… Read More
  • 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
  • show processing image when click on button and freeze background in asp.net                            This post gives some useful information to beginner's  those don't know to design the page. here i am just … 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

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