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;}">
i dont know much javascript, i just need to know how to stop the user from entering aspace into the textbox - is this possible, if its not possible to sto this initially is it possible to alert them on formsubmit so they can go back and change?
Zvonko
Did you test any of my upper proposals?
apresto
ASKER
no im not sure which one it is
i didnt write the example i gave above about only numbers being allows into the text field i got it from another question and it doesnt relate to what i need to do i just wanted a similar feature where i can put some javasript actually in the Input tag using the keypress event
Hi Zvonko, i know i closed the question but i just realised that this code you gave me that i accepted doesnt allow me to enter numbers - couldyou possibly amend this so that it allows everything BUT a blank space (space bar)?
I can give you that, but if you realy allow ANYTHING but space, then you allow also %&$@#, and so on. Do you realy want that?
apresto
ASKER
ah i see thats a good point!
is there a way to disallow space and those characters?
i can open another question if you like - let me know if its "new question worthy" and ill open another one, its not a problem
thanks - Good call
Zvonko
Simply say what characters you want to allow and I can make it here.
For example, do you want this characters to be allowed: a-z0-9
Any else character?
Also perhaps you want to allow that first character is alpha, and second and following can be alpha or digit
You can also check for at least three characters value length.
apresto
ASKER
wow thats more than i ever hoped for if you could create something that:
allows only
- a-z
- A-Z
- 0 - 9
does not allow <spacebbar>
has to begin with letter
and must be atleast 3 digits that would be fantastic
apresto
ASKER
seeing as this is only a 250 question i will open another question for points for you for the great help
<input type="text" name="numOnly" size="10" onKeyUp="if(this.value.mat
And this for names:
<input type="text" name="numOnly" size="10" onKeyUp="if(this.value.mat
Only problem with the meta character \W is that it would allow names like this one: 11111111
So if you like to have only characters you have to use this:
<input type="text" name="numOnly" size="10" onKeyUp="if(this.value.mat
If you like to add more acceptabe characters to the set, then add them to the square braces set:
<input type="text" name="numOnly" size="10" onKeyUp="if(this.value.mat
The upper expression does add the dash and the underscore character to allowed character set.