Is it possible to determine with the help of JS whether the abbreviation, for example, such "FCAG125A / RR125BV3", contains Cyrillic letters? If so, what properties and methods will help solve this problem?

    1 answer 1

    Alternatively, you can use regular expressions and the .test () method.

    The following code example will suffice:

    let regexp = /[а-яё]/i; regexp.test(string); 

    And an example of the result:

     let string = 'ваываывЫФАЫВАsdkfjlsdkfer'; let string1 = 'dkfjlsdkfer'; let string2 = 'ваываыв'; let string3 = '34234234'; let regexp = /[а-яё]/i; console.log(regexp.test(string)); console.log(regexp.test(string1)); console.log(regexp.test(string2)); console.log(regexp.test(string3)); 

    • one
      It may be better to use the i - ignore case flag. Then the record is shorter and clearer /[а-яё]/i . - Stepan Kasyanenko
    • @StepanKasyanenko Thanks for the improvement, I will take note, I will correct it - Sergey Glazirin
    • And if it is necessary to paint the found Cyrillic characters in another color, will the test () method be enough or will it be necessary to use exec ()? - ikar
    • one
      @ikar, one test() method will not be enough, since it only returns true or false depending on whether there are Russian characters there. And in order to paint the Cyrillic alphabet, you also need to break the string into substrings, most likely it is better not to fit exec() , but match () and wrap it in <span> to color individual ones (this is my vision of the picture). For such a case, it seems to me better to ask a new question. - Sergey Glazirin