Can you please tell me how to check for Latin on pure js (so that only Latin letters can be entered)

Closed due to the fact that the essence of the question is not clear to the participants 0xdb , αλεχολυτ , Misha Saidov , Kosta B. , LFC 26 Jan at 7:32 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • five
    for example like this /^[az]*$/i - Grundy
  • Is it really clean? Can you comment, if not more difficult? - Roma Prokopets
  • nothing clearer :) RegExp - Grundy
  • and there are ways to "simpler"?) - Roma Prokopets

2 answers 2

Well, there is how the varinat on the code to compare the characters have codes and sranvit on them that type Taekova

 window.onload = () => { var T = document.getElementById('cli'); var B = 'A'.charCodeAt(0); var E = 'Z'.charCodeAt(0); T.onkeyup = (e) => { for (let i = B; i != E; i++) { var C = event.target.value; for (let j = 0; j < C.length; j++) { if (C[j].charCodeAt(0) < i || C[j].charCodeAt(0) > i) { C.replace(C[j], ''); console.log(`Current: ${C[j].charCodeAt(0)} - Target: ${i} J: - ${j}`); } } } } } 

so here is not what js

 <form action=""> <input type="text" id="cli" pattern="[A-Za-z]"> <button type="submit">send</button> </form> 
  • events here, too difficult for my level. I need the usual option .. there are two input and a button. In the first input login, in the second password. you need to do so that when the water of non-Latin characters pop up the alert "right or wrong" through if else. All this should work when the button is clicked - Roma Prokopets
  • updated the answer uk - Sasuke
  • @ RomaProkopets, it is impossible to show an alert without events - Grundy

Here it is possible.

 $('form').on('keydown',(e) => { var regExp = '^[a-zA-Z]+$'; e.target.value.search(regExp) == false ? '' : $(e.target).val($(e.target).val().substr(0,$(e.target).val().length-1)) }).on('keyup',(e) => { var regExp = '^[a-zA-Z]+$'; e.target.value.search(regExp) == false ? '' : $(e.target).val($(e.target).val().substr(0,$(e.target).val().length-1)) }) 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script> <form action="#"> <input type="text"> <input type="submit"> </form>