Saturday, 12 May 2012

Copy only numbers from textbox using javascript

 In this Example i am Describing , Copy only numbers or numeric characters in the text box..
here if we copy characters + numbers it will copy only Numbers

Here is the Example :

1)Copy data from Textbox :




2) Paste in another Textbox :


3) Final OUTPUT :



TextBox oncopy :

oncopy="return CopyNumericOnly(this);"

Script :

function CopyNumericOnly(obj) {
            var textboxvalue = obj.value;
            var strValidChars = "0123456789";
            var strChar;
            var FilteredChars = "";
            for (d = 0; d < textboxvalue.length; d++) {
                strChar = textboxvalue.charAt(d);
                if (strValidChars.indexOf(strChar) != -1) {
                    FilteredChars = FilteredChars + strChar;
                }
            }
            window.clipboardData.setData('Text', FilteredChars);
            return false;
        }

 



Related Posts:

  • 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
  • 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
  • Image Mouse Hover in asp.net To show image in particular div when mouse hover on the image using asp.net   Script <script type="text/javascript" language="javascript">         function ShowToolTip(con) {   &n… 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
  • 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

2 comments: