Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
Check if the first letter that appears in the string is Cyrillic or not

I am trying to check if the first letter in a string is a Cyrillic letter.

Here is what I have until now, but the problem is that if the string starts with a digit it also fires the pattern:

$(document).on('keydown keyup', '#userBox', function() {
  $('#result').html('');
    if (/[a-zA-Z]*[^A-Za-z \d]+[a-zA-Z]*/.test(this.value)) {
      $('#result').html('Cyrillic');
    } else {
      $('#result').html('Non-Cyrillic');
    }
    if ( $(this).val().length === 0) {
          $('#result').html('');
        }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="userBox" autocomplete="off" type="text"  autofocus="true" placeholder="Type your message"> <span id="result"></span>

also using the solution from this post How to match Cyrillic characters with a regular expression will produce the same result

$(document).on('keydown keyup', '#userBox', function() {
  $('#result').html('');
    if (/[\p{IsCyrillic}]/.test(this.value)) {
      $('#result').html('Cyrillic');
    } else {
      $('#result').html('Non-Cyrillic');
    }
    if ( $(this).val().length === 0) {
          $('#result').html('');
        }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="userBox" autocomplete="off" type="text"  autofocus="true" placeholder="Type your message"> <span id="result"></span>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use

/^\P{L}*\p{Script=Cyrl}/u

See the regex demo. Note the /u flag that makes it possible to use Unicode property/category classes inside ECMAScript 2018+ compliant regular expressions. Details:

  • ^ - start of string
  • \P{L}* - zero or more chars other than letters
  • \p{Script=Cyrl} - a Cyrillic char

$(document).on('keydown keyup', '#userBox', function() {
  $('#result').html('');
    if (/^\P{L}*\p{Script=Cyrl}/u.test(this.value)) {
      $('#result').html('Cyrillic');
    } else {
      $('#result').html('Non-Cyrillic');
    }
    if ( $(this).val().length === 0) {
          $('#result').html('');
        }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="userBox" autocomplete="off" type="text"  autofocus="true" placeholder="Type your message"> <span id="result"></span>

Bonus:

To make sure the first char of a string is a Cyrillic char use

/^\p{Script=Cyrl}/u

If you want to support leading optional whitespaces before the first char of a string that is a Cyrillic char:

/^\s*\p{Script=Cyrl}/u
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda