Suresh Mali
Suresh Mali

Reputation: 27

How to create autocomplete which only starts with either first letter or any other letter in the string starting after space

In this fiddle autocomplete if I type letter "s" it shows listing which starts with "s" but I need all the listing starting with "s" and having space before "s".

Means if I type "s" then i should get both kind of results like "suraj kumar" & "nimish shah". Please someone suggest me solution.

jsfiddle.net/9R4cV/701/

Upvotes: 0

Views: 92

Answers (1)

archimede
archimede

Reputation: 736

I'm not a RegExp guru, so there might be more clever solutions, but here's an updated fiddle: http://jsfiddle.net/9R4cV/702/

    source: function(req, responseFn) {
    var re = $.ui.autocomplete.escapeRegex(req.term);
    var matcher = new RegExp( "^" + re, "i" );
    var matcher2 = new RegExp( "\\s" + re, "i" );
    var a = $.grep( aTags, function(item,index){
        return matcher.test(item) || matcher2.test(item);
    });
    responseFn( a );
}

Upvotes: 2

Related Questions