Alihuseyn Alihuseyn - 2 years ago 99
Javascript Question

JQuery Autocomplete search both to letters

I implemented autocomplete which fetch all data with ajax post from database and add them to autocomplete as item. which is shown below

url: "--url--",
dataType: 'jsonp',
success: function(data) {
source: function( request, response ) {
var lookup = jQuery.ui.autocomplete.escapeRegex( request.term );
var matcher = new RegExp( "^" + lookup, "i" );
response( jQuery.grep(data, function(item){
return matcher.test(item);

The data after post come as :

data = ['Berti','Simon','Çarli','Cherpa'];

While doing typing in input field for letter "C" only "Cherpa" shown but I try to show "Çarli" also to user. How can I handle it and give option to user both letter "C" and "Ç"? Thanks in advance.

Answer Source

You can try :

var lookup = jQuery.ui.autocomplete.escapeRegex( request.term );
if(lookup.indexOf('C') != -1 || lookup.indexOf('Ç') != -1) {
    lookup.replace("C", "(C|Ç)");
    lookup.replace("Ç", "(C|Ç)")
var matcher = new RegExp( "^" + lookup, "i" );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download