Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda