You need to check some text for the presence of letters. That is, I want to create a function that will receive the text, look for letters in it and, if it finds one, run the first function, if not, then the second one.

The whole trouble is that I do not know how this can be realized.

  • Please give an example of text without letters, it is terribly interesting to look at it. - Darth
  • Just to say that there are only numbers - Ezdrael

2 answers 2

You can use a regular expression ( i to ignore case):

 if (/[a-zа-яё]/i.test(inputText)){ containsLetters(inputText); } else { doesNotContainLetters(inputText); } 

PS Checks only for the presence of Latin letters or letters of the Russian language.

  • Thank you, that's enough for me. - Ezdrael

If the isNaN argument is not a number, then it is automatically converted to a number, if not, then the string with characters. Works with all characters

 alert(isNaN(prompt("Введите строку", "строка"))); 

https://learn.javascript.ru/number

  • : - it seems like not a letter - Grundy
  • Some characters can be checked separately, it's not so scary - Danilkinkin
  • There are numbers and spaces in the text. So your option disappears. - Ezdrael
  • But you just need to check availability? This does not mean that it should consist only of letters. Formulate the question more specifically - Danilkinkin
  • "445 letter 445 letter" will work for example - Danilkinkin