Jump to content

got confused...what is this??


frozentree

Recommended Posts

i find it difficult to understand this tutorial on events.<html><body><script type="text/javascript">function noNumbers(e){var keynumvar keycharvar numcheckif(window.event) // IE{keynum = e.keyCode}else if(e.which) // Netscape/Firefox/Opera{keynum = e.which}keychar = String.fromCharCode(keynum)numcheck = /\d/return !numcheck.test(keychar)}</script><form><input type="text" onkeydown="return noNumbers(event)" /></form></html>the line " numcheck=/ \ d / " got me spinning in the head. " / \ d / " mean what?? please guide me ....... " d" means date?? or data?

Link to comment
Share on other sites

If I was You I would filter out the numbers like this:

function noNumbers(e){try{var key = (e.which) ? e.which : event.keyCode}  catch(err){}return ((key == 8 || key > 31) && (key < 48 || key > 57));}

Just added try/catch block when I found that Linux has some odd event with numpad keys.(some event causes undefined error)Please use onkeypress, it works much better than onkeydown:<input type="text" onkeypress="return noNumbers(event)" />edit:sorry, You are reading tutorial of events, not filttering numbers? Anyway, in this (my private) tutorial we learn how to play with events and errors and etc. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...