Errors when entering incomplete regex into filter?

Errors when entering incomplete regex into filter?

bchurchillbchurchill Posts: 3Questions: 0Answers: 0
edited July 2011 in Bug reports
Hi all,

I've just got regular expression filtering setup on individual columns with smart filtering turned off. However, when the user starts typing in a regular expression but is not yet finished (like "[23") javascript errors come up. To the user the functionality works; when they finish typing in their expression ("[234]<") it filters properly. However I would like to eliminate the associated error. It comes from the minimized jquery file. The errors are regarding the unfinished regular expression, e.g. "trailing \ in regular expression" or "unterminated character class".

If you want to see my code/exactly what's happening, you can visit http://dana.ucc.nau.edu/~brc77. You can reproduce the errors in Firefox 3.6 by clicking the "Use regular expression filtering" check and then typing a '[' into any of the filter boxes. (and if you have suggestions on making the checkbox more responsive, that would be appreciated too...).

Thanks
Berkeley

Replies

  • bchurchillbchurchill Posts: 3Questions: 0Answers: 0
    Anyone?
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited July 2011
    you could take the text from the textboxes and create your own RegExp objects, wrapped in try..catch blocks

    [code]
    try {
    var re = new RegExp(textbox_value); // will throw exception?
    oTable.fnFilter(textbox_value);
    }
    catch (err) {
    // ignore.. just trapping error and avoiding calling fnFilter.
    }
    [/code]

    but if the user doesn't see it, does the error really happen? *omm*
  • bchurchillbchurchill Posts: 3Questions: 0Answers: 0
    Ah, that worked nicely! I also put some code in the catch block to turn the field red when the input wasn't valid.

    Question though: is the default javascript RegExp object the same one that jQuery/datatables uses for regular expressions? Or does jQuery do something custom? If it is custom, is there the chance that a regular expression will be valid for one implementation but not the other, causing problems?
This discussion has been closed.