Javascript Begins With match regex

Got the following filter function but it isn't working. How should I modify it to match items that begin with the args.SearchString?

function myFilter(item, args) {
    var filterFieldName = columns[$('#filter-select-column').find(':selected').val()]["field"];
    var val = (item[filterFieldName].match("^" + args.searchString + "/i"));
    return val;
}

Open in new window

LVL 26
Eddie ShipmanAll-around developerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
käµfm³d 👽Connect With a Mentor Commented:
Use the RegExp constructor:

var val = (item[filterFieldName].match(new RegExp("^" + args.searchString, "i")));

Open in new window

0
 
Eddie ShipmanAll-around developerAuthor Commented:
Running into another problem but this is correct, thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.