Click to See Complete Forum and Search --> : Stop user from using Paste??


clarkw
03-25-2005, 12:14 PM
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.

How do I go about blocking the use of "paste"?

Is there a better solution

Thanks

ClarkW

Jona
03-25-2005, 12:27 PM
Why not just remove all punctuation characters automatically onKeyPress?

clarkw
03-25-2005, 01:39 PM
Jona,

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.

the tree
03-25-2005, 01:44 PM
I don't think that's what Jona was saying, hows about, onKeyPress, you take away all the punctuation from the field.

Jona
03-25-2005, 01:54 PM
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.

ray326
03-25-2005, 02:29 PM
Use an onblur() handler to validate the field value.

clarkw
03-25-2005, 02:34 PM
OK, you are correct - onKeyPress for my SUBMIT, remove the punctuation. Thanks.

ClarkW

Jona
03-25-2005, 06:09 PM
OK, you are correct - onKeyPress for my SUBMIT, remove the punctuation. Thanks.

ClarkW
It would probably be compatible with more browsers if you used onsubmit in the actual form tag itself, rather than "onKeyPress" on your submit button.

fredmv
03-26-2005, 10:38 PM
It would probably be compatible with more browsers if you used onsubmit in the actual form tag itself, rather than "onKeyPress" on your submit button.It would also work in more instances (e.g., if the user submits the form by actually clicking the submit button instead of pressing Enter).

js_prof_cons
03-26-2005, 11:01 PM
It would also work in more instances (e.g., if the user submits the form by actually clicking the submit button instead of pressing Enter).However, if the tex field is checked onkeyup, the field will be validated before the user presses enter, or clicks the submit button:<input type="text" ... onkeyup="this.value=this.value.replace(/?!/g,'')">Of course, you'd add in all the punctuation, escaping \ some where necessary.

ray326
03-27-2005, 12:47 AM
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().

js_prof_cons
03-27-2005, 09:57 AM
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.