BPM, Workflow, and Case

Expand all | Collapse all

RegExp.prototype.test() doesn't work

  • 1.  RegExp.prototype.test() doesn't work

    Posted Tue August 24, 2021 12:53 PM
    Good day!

    I would like to know why method test() from RegExp doesn't work in IBM BPM? For instance:

    I have a code on onClick event which does simple thing:

    console.log('testing:', /^\d{8}$/.test("25138987")); consoling true/false based on string inside test() method, but the thing is, even if it is a simple regExp that says string must be exaclty 8 digits long, it returns false no matter what, could you please provide some info to fill my missknowledge gap? Thank you!

    Vladislav Tishchenko

  • 2.  RE: RegExp.prototype.test() doesn't work

    Posted Tue August 24, 2021 09:35 PM
    When placing that RegEx into the inline event for a button control, I observed the same behavior.

    I tried a few variations that didn't work, but was able to get something working by creating a function in a Custom HTML control and then calling that function in the on click event of the button. I was writing this up to send and managed to find the reason we observed the original behavior.


    At the bottom of the above link, you will see a note that we need to have \\d instead of \d in the RegEx. So what we saw with it always returning false was because it wasn't interpreting the RegEx as expected and when it was evaluated, it was just /^d{8}$/

    The following works as you expected console.log('testing:', /^\\d{8}$/.test("25138987"));

    Given this though, I would probably just keep the RegEx in a function on the coach via the Custom HTML control, or better yet, as a part of whatever validation function you plan to run on your composite coach views for better reuse.

    Rackley Boren