Search code examples
javascriptcase-sensitivecase-insensitive

JavaScript / case-insensitive


I have this function to filter values in order to implement an auto-complete feature:

 store.filter(new Ext.util.Filter({
    filterFn: function (object) {
        var match = false;
        Ext.Object.each(object.data, function (property, value) {
        match = match || value.match(Ext.getCmp('search_input_text').getValue());

        });
        return match;
      }

I need it to be case-insensitive so that both upper and lower cases would be the same.

value.match(Ext.getCmp('search_input_text').getValue());

something like LIKE in sql. How can I do that ?


Solution

    1. Regexp have a constructor using string arguments.
    2. if you need a boolean result don't use match, use test instead.

      store.filter(new Ext.util.Filter({
          filterFn: function (object) {
              var match = false;
              Ext.Object.each(object.data, function (property, value) {
                  var filterValue = Ext.getCmp('search_input_text').getValue();  
                  var r = new RegExp(filterValue, 'i'); 
                  match = match || r.test(value);  
              });
              return match;
          }
       ...
       }