www.webdeveloper.com
Results 1 to 12 of 12

Thread: Stop user from using Paste??

  1. #1
    Join Date
    Mar 2005
    Posts
    3

    Stop user from using Paste??

    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

  2. #2
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Why not just remove all punctuation characters automatically onKeyPress?
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  3. #3
    Join Date
    Mar 2005
    Posts
    3
    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.

  4. #4
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,972
    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.

  5. #5
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    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.

  6. #6
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    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

  7. #7
    Join Date
    Mar 2005
    Posts
    3
    OK, you are correct - onKeyPress for my SUBMIT, remove the punctuation. Thanks.

    ClarkW

  8. #8
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Quote Originally Posted by clarkw
    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.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  9. #9
    Join Date
    Jul 2003
    Location
    Boston Area, Massachusetts
    Posts
    3,489
    Quote Originally Posted by Jona
    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).

  10. #10
    Join Date
    Mar 2005
    Posts
    253
    Quote Originally Posted by fredmv
    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:
    HTML Code:
    <input type="text" ... onkeyup="this.value=this.value.replace(/?!/g,'')">
    Of course, you'd add in all the punctuation, escaping \ some where necessary.

  11. #11
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    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

  12. #12
    Join Date
    Mar 2005
    Posts
    253
    Quote Originally Posted by ray326
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles