How reference a component with JavaScript

Hi i have a question , i know that i can put pure code Javascript with Vaadin Like JavaScript.eval(

“…”); but if i want to reference a textfield with javascript ? i mean make a event like onkeypress and put that event in the textfield when the screen appear.
A good example is make a validator of only letters and numbers , but only with Javascript not going to backend , is that possible ?

Thanks !

You don’t want to reference any componets through a JS.eval. In order to do that kind of stuff I would recommend creating an extension,

You can also look at the one client side validator addon in the directory if that might satisfy your needs