Thanks for the reply!
This is what I could come up with
if(window.event) // IE
keynum = e.keyCode;
else if(e.which) // Netscape/Firefox/Opera
keynum = e.which;
<input type="text" name="firstname" onkeydown="return checkChar(event)">
<input type="text" name="lastname">
The problem is that the shift press is also being treated as a event and when I click on number 7 for & ,the ascii code obtained is 55 which is for number 7 and not for & . So now 7 and & are not printing but I dont want only special characters.