How can I retrieve the value of a PASTE (copy-pasta) event in a GWT TextBox?

Posted by dominicbri7 on Stack Overflow See other posts from Stack Overflow or by dominicbri7
Published on 2011-06-23T19:19:17Z Indexed on 2011/06/24 0:22 UTC
Read the original article Hit count: 238

Filed under:
|
|
|
|

Hello fellow SO members,

I want to prevent the user from copy-pasting values in my TextBox IF AND ONLY IF the values do not respect a certain condition.

For instance, I created a DigitsOnlyTextBox which will be used for phone numbers. I already made it so only Character.isDigit characters can be typed into the box, and the user cannot copy-paste values into it, using :

this.sinkEvents(Event.ONPASTE);

and

public void onBrowserEvent(Event event) {
    super.onBrowserEvent(event);

    // Permet d'empêcher le copier-coller, donc d'entrer des caractères non-numériques

    if (event.getTypeInt() == Event.ONPASTE) {
        event.stopPropagation();
        event.preventDefault();
    }
}

But I'd like to verify if the copy-pasted String is "digits only" and if so, let the event happen (therefore the text added).

tl;dr : see title

Thank you for your time. Sincerely.

© Stack Overflow or respective owner

Related posts about java

Related posts about events