I have a text box that I am currently blocking punctuation on via block key press. This does not stop the user from "pasting" text containing invalid characters.
I do block all punctuation onKeyPress, but if you paste the information in, it does not read it as a KeyPress. Then when you do the submit it enters the pasted information as text - complete with the punctuation.
I don't think that's what Jona was saying, hows about, onKeyPress, you take away all the punctuation from the field.
Disclaimer. (1) Whilst I will help you sometimes, if I feel like it, and my advice in relation to your actual question will be of good quality: my posts are to be taken with a pinch of salt. I will be sarcastic, deploy irony and include obscure cultural references for my own amusement without warning.
(2) You will gain nothing from complaining, and if you try to argue with me then you will not win. No matter how noble your battle seems, I am still better than you, don't be an hero.
If it's that much of a problem, you run a setInterval to strip out punctuation marks every few seconds. Your problem will occur when you find that anyone can disable JavaScript and easily bypass your script, so you will need a server-side solution for this as well.
Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.
Use an onblur() handler to validate the field value.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." Brian W. Kernighan
Following on with this "my event's bigger than your event" thread, onblur() gets the job done without having to deal with every keystroke yet with a little more interaction than waiting to validate onsubmit().
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." Brian W. Kernighan
Following on with this "my event's bigger than your event" thread, onblur() gets the job done without having to deal with every keystroke yet with a little more interaction than waiting to validate onsubmit().
I would take the assumption that the punctuation would want to be removed in real time. Otherwise, onblur, as you say, is the best option.
Bookmarks