Why don't UTF-8 characters work in jquery textcomplete?

I am using jquery-textcomplete autostart in my web application. It works great for English and Russian letters. But it does not work for certain special letters, such as "ҷ" .

The code:

$('.form-control').textcomplete([{
  words: ['ҷ', 'ҷҳ', 'english'],
  match: /(^|[^\w-ҷ])([\w-]{2,})$/i,
  search: function(term, callback) {
    callback($.map(this.words, function(word) {
      return word.indexOf(term) === 0 ? word : null;
    }));
  },
  index: 2,
  replace: function(word) {
    return '$1' + word + ' ';
  }
}]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.textcomplete/1.8.4/jquery.textcomplete.min.js"></script>

<textarea class="form-control"></textarea>
Run codeHide result

Here the word 'ҷ'and 'english'work, but 'ҷҳ'do not. How can i fix this?

I need the following letters to work: ғ,ӯ,қ,ҳ,ҷ,ӣand -.

+4
source share
1 answer

A similar question has already been given.

$('#textcomplete').textcomplete([{
  words: ['ҷ', 'ҷҳ', 'english'],
  match: /(^|\S*)([^\u0000-\u007f]{2,}|\w{2,})$/,
  search: function(term, callback) {
    callback($.map(this.words, function(word) {
      return word.indexOf(term) === 0 ? word : null;
    }));
  },
  index: 2,
  replace: function(word) {
    return word + ' ';
  }
}]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.textcomplete/1.8.4/jquery.textcomplete.min.js"></script>

<textarea id="textcomplete"></textarea>
Run codeHide result
+1
source

Source: https://habr.com/ru/post/1691577/


All Articles