troubleshooting Question

OnKeyDown Alert - Want to disable spacebar

Avatar of apresto
aprestoFlag for Italy asked on
JavaScript
16 Comments1 Solution694 ViewsLast Modified:
Hey guys, simple question probably, i am working on a user registration form and i want their UserName to be spaceless (no spaces), is there a way to put a little OnKeyDown procedure in the username Textfield that will either alert the user when they atempt to hit space or will just not let them hit space

Example:

This one alerts when the user attempts to hit anything on the keyboard that isnt a number:

<input type="text" name="numOnly" size="10" onkeypress="if(isNaN(String.fromCharCode(event.keyCode))){alert('Please only enter numbers.');return false;}">

?

Thanks guys
ASKER CERTIFIED SOLUTION
Zvonko
Systems architect
Join our community to see this answer!
Unlock 1 Answer and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros