Prevent user to type numbers and symbols. However problem something use Capslock Buttons

Asked

Viewed 34 times

0

When I click the input and hit Caps Lock, Backspace, it sends the patch message. for example, I type the normal and safe Backspace input to delete everything, when it comes at the end it shows the "fill only with letters" message. I used this code (name.match(/ [a-z" "A-Z_]+$/) but would like to release Capslock and Backspace.

//Reservation validation
const nameinput = document.getElementsByClassName('names');  
const emailinput = document.querySelector('input[name="email"]');  
const submitinput = document.querySelector('input[name="submitreservation"]');  
console.log(nameinput);  
Array.from(nameinput).forEach(function (item) {
item.addEventListener('keyup', function (e) {
var name = e.target.value;

    if (name.match(/^[a-z" "A-Z_]+$/)) {
        e.target.value = name.toUpperCase();
    }
    else {
        console.log(e.target.value)
        alert('Digite apenas letras !');
        e.target.value ="";
    }

})
})
  • I don’t quite get it, you wish there was no Capslock and Backspace message?

  • That Alvaro. When I click on the input and Backspace grip if it is empty, msm thing with Caps appears the error. I do not want it. only with numbers and symbols

  • the friend closed the post, but has nothing to do with my question

  • i flagged the moderators pq your question is not duplicated and on validation with regex

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.