function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ARVIND ADMIN 6ARVIND ADMIN 6 

working with Alpha-Numeric keys in JavaScript

i have writen the code for Alpha-Numeric keys  but it working for all keys in the keyboard (delete,backspace,enter,arrowkeys.............)

The piece of code is 
<apex:page >
  <script>
  function keyup()
  {
  alert("key up calles");
  }
  function keypress()
  {
  alert('key press calles');
  }
  function keydown()
  {
  alert('key down calles');
  }
  </script>
  <apex:form >
  Name:<input type = "text" onkeyup="keyup()"/><br/>
  Email:<input type = "text" onkeypress="keypress()"/><br/>
  PhoneNumber:<input type= "text" onkeydown= "keydown()"/><br/>
  </apex:form>
  
</apex:page>

 
Arunkumar RArunkumar R
You may use the below code,
 
<apex:page>
<head>
    <style type="text/css">
        body
        {
            font-size: 9pt;
            font-family: Arial;
        }
    </style>
</head>

    Alphanumeric value:
    <input type="text" id="text1" onkeypress="return IsAlphaNumeric(event);" ondrop="return false;"
        onpaste="return false;" />
    <span id="error" style="color: Red; display: none">* Special Characters not allowed</span>
    <script type="text/javascript">
        var specialKeys = new Array();
        specialKeys.push(8); //Backspace
        specialKeys.push(9); //Tab
        specialKeys.push(46); //Delete
        specialKeys.push(36); //Home
        specialKeys.push(35); //End
        specialKeys.push(37); //Left
        specialKeys.push(39); //Right
        function IsAlphaNumeric(e) {
            var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode;
            var ret = ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode));
            document.getElementById("error").style.display = ret ? "none" : "inline";
            return ret;
        }
    </script>
</apex:page>

Reference: http://www.aspsnippets.com/Articles/Allow-only-AlphaNumeric-Alphabets-and-Numbers-characters-and-space-only-in-TextBox-using-Javascript.aspx