Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. How to Clear the Numbers..

How to Clear the Numbers..

Scheduled Pinned Locked Moved Web Development
javascripthelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dotnetkanna
    wrote on last edited by
    #1

    Hi everyone, Help need in javascript,Im having a textbox with combination of special characters and numbers while on pressing the delete key(keycode 46) it should be clear only the numbers and not the special characters..How should i achieve this one.. Thnx in advance.. Regards Kanna

    T 1 Reply Last reply
    0
    • D Dotnetkanna

      Hi everyone, Help need in javascript,Im having a textbox with combination of special characters and numbers while on pressing the delete key(keycode 46) it should be clear only the numbers and not the special characters..How should i achieve this one.. Thnx in advance.. Regards Kanna

      T Offline
      T Offline
      Torsten Mauz
      wrote on last edited by
      #2

      The below will work in IE. It will be easy enough to make cross browser - I just don't have the time at the moment (but the same principals will apply).

      function checkKey()
      {
      var key = event.keyCode;
      var ch = '';

      if (document.selection) 
      {
          var sel = document.selection.createRange();
          if(key == 46)
          {
              sel.expand("character");
              ch = sel.text;
              if(isNaN(ch))
                  return false;
          }
          if(key == 8)
          {
              sel.move("character", -1);
              sel.expand("character");
              ch = sel.text;
              if(isNaN(ch))
                  return false;
          }
      }
      

      }

      HTH

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups