T
T
TheSnegok2021-08-29 21:19:02
JavaScript
TheSnegok, 2021-08-29 21:19:02

How to allow only English characters to be entered?

I googled and found only this:

<input
  type="text"
  onKeyPress={(e) => validation(e)}
/>

const validation = (e) => {
  let input = e.target.value;
  input = input.replace(/[A-Za-z]/, '');
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Suntsev, 2021-08-29
@TheSnegok

const validation = (e) => e.target.value = input.replace(/[A-Za-z]/g, '');
<input
  type="text"
  onChange={validation}
/>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question