title: How could I get the same result using “addEventListener” ('keyup', function), instead of using “onkeyup” as HTML attribute?
body: <p>I found this original code. My concern is the validation of the regular expression. You can‘t type numbers because of the function:</p>
  <pre><code>&lt;form&gt;
  &lt;label for=&quot;username&quot;&gt;Chosse a Username:&lt;/label&gt;
  &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username1&quot; onkeyup=&quot;lettersOnly(this)&quot;&gt;
  &lt;/form&gt;
  
  &lt;script&gt;
  function lettersOnly(input){
              var regex = /[^a-z]/gi;
              input.value = input.value.replace(regex, &quot;&quot;);
  }
  &lt;/script&gt;
  </code></pre>
  <p>As per I read, those events like <code>onkeyup</code> should not be placed like an attribute in the HTML, so I found, after longer hours, another solution WITHOUT the <code>onkeyup</code> attribute, as follows:</p>
  <pre><code>&lt;form&gt;
  &lt;label for=&quot;username&quot;&gt;Choose a Username:&lt;/label&gt;
  &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;texto1&quot;&gt;
  &lt;/form&gt;
  
  &lt;script&gt;
  let user = document.getElementById('texto1');
              user.onkeyup = function() {
              var regex = /[^a-z]/gi;
              user.value = user.value.replace(regex, &quot;&quot;);
             }
  &lt;/script&gt;
  </code></pre>
  <p>However, I don‘t really find accurate information if the ON-prefix-events like ONkeyup are still good standards. Is there a way I can get the same effect you get in these two examples but using the <code>addEventListener</code>? I tried the following code with lots of variants but nothing. What can you suggest me?</p>
  <pre><code>&lt;form&gt;
  &lt;label for=&quot;username&quot;&gt;Chosse a Username:&lt;/label&gt;
  &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username2&quot;&gt;
  &lt;/form&gt;
  
  &lt;script&gt;
  function lettersOnly(input){
              var regex = /[^a-z]/gi;
              input.value = input.value.replace(regex, &quot;&quot;);
          }
              input.value.addEventListener('keyup', lettersOnly);
  &lt;/script&gt;
  </code></pre>
  <p>What Am I doing wrong in the last example?</p>