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>