Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

317
Views
Javascript, convert inline html js to normal js

So I have this input tag:

<input ... onkeypress="return /^[A-Za-z0-9 -]*$/.test(event.key)" id="id_title">

And I want it to accept only numbers, letters and spaces. I wonder how to rewrite it in my JS file with jQuery in modern JS version, because all methods from the Internet with old JS are crossed out. Like in here, https://www.codegrepper.com/code-examples/javascript/allow+only+letters+in+input+javascript onkeypress or keyCode methods are not working now. They are crossed out.

$('#id_title').on('keydown', function() {  

     let regex = /^[A-Za-z0-9 -]*$/ // accepts only letters, numbers and spaces
     ... // how to continue?

}

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this -

$('#id_title').on('input', function(event) {  
    let regex = /^[A-Za-z0-9 -]*$/;
    return regex.test(event.key);
});

Check out the MDN docs on the test method!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!