Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

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

1 Solution
käµfm³d 👽Commented:
Use the RegExp constructor:

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

Open in new window

EddieShipmanAuthor Commented:
Running into another problem but this is correct, thanks.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now