Skip to main content
gubhare
Participating Frequently
May 4, 2015
Question

regex javascript not working in Captivate8 but works fine in CP6

  • May 4, 2015
  • 2 replies
  • 1295 views

Hello All,

I was recently come across this problem in captivate 8. Let me explain what I am trying to achieve.

I am working for a company where I need to validate the UK driving licence format. I have found the solution using Regex. It works perfectly in my JSFiddle, Check the working example here

https://jsfiddle.net/gubhare/uxmtbL88/

However if I run the same javascript  through captivate 8 (run time/ published) it does not work and it always comes up with "Dricing licene format incorrect" even when its the correct format.

So I tried to get some help from Regex experts. Please see the blog here

Re: Regex problem

One of the expert on this blog has suggested to me that he tried my code in Captivate 6 and it works fine as expected but not in Captivate 8.

Surely there is some kind of bug in captivate 8 which is preventing proper execution of Regex through Javascript.

I will really appreciate if anyone from Adobe Support or  any Captivate Guru can help me out with this issue.

Thanks

Ganesh

    This topic has been closed for replies.

    2 replies

    Participating Frequently
    March 27, 2017

    Hello Everyboby,

    I have the same problem with CPT9.

    I can conclude that the problem is the use of backslash \ character !

    When I use \d , \w or \. in REGEX with the Execute Javascript, it doesn't work, always FALSE value even if it's correct p.e. : CONSA123

    First example:

    var BC_ID_Smart= window.cpAPIInterface.getVariableValue('v_BC_ID_Smart') ;

    var re = /^(CONSA|CONSU|ASTRO|SPONS|COMET|COSMO|ATLAS)\d{3}$/g ;

    if (re.test(BC_ID_Smart)) {

    window.cpAPIInterface.setVariableValue('v_correct_ID_Smart',1);

    } else {

    window.cpAPIInterface.setVariableValue('v_correct_ID_Smart',0);

    }

    When I don't use \d but I use its equivalent expression [0-9] , it works perfectly !

    var re = /^(CONSA|CONSU|ASTRO|SPONS|COMET|COSMO|ATLAS)[0-9]{3}$/g ;

    Another example:

    To do email validation, I need to use \. to specifically use a dot (or more) in email.

    and I replaced \w by [a-zA-Z0-9_]

    But there is a problem, Captivate see only "."(the dot and not backslash) witch means "any character" in REGEX!.

    I can conclude that captivate skip or doesn't like the use of \ (backslash):

    var BC_email= window.cpAPIInterface.getVariableValue('v_BC_email') ;

    var re = /^([a-zA-Z0-9_+-]+(\.[a-zA-Z0-9_+-]+)*)@([a-zA-Z0-9]+(-*[a-zA-Z0-9])+\.)+([a-zA-Z]{2,})$/g ;

    if (re.test(BC_email)) {

    window.cpAPIInterface.setVariableValue('v_Etat_email',1);

    } else {

    window.cpAPIInterface.setVariableValue('v_Etat_email',0);

    }

    My REGEX email validation, then, doesn't work correctly in Captivate9 because of the use of \. and there is no equivalent to bypass the issue like the first example....

    PLEASE, Abobe conceptor and programmers, FIX that BUG asap!!!!

    Lilybiri
    Legend
    March 27, 2017

    Did you put that in the JS window in Captivate, or in the HTML or JS file  as TLCMediaDesign recommended?

    BTW this is a user forum. To be heard by the Adobe people, log a feature request or a bug report, please, don't shout at other users like me.

    Participating Frequently
    March 27, 2017

    I use it in JS window in Captivate and in Conditional Actions  ( IF Then "Execute Javascript " Else ) in "Advanced action" .

    TLCMediaDesign
    Inspiring
    May 4, 2015

    Try putting the script in a function in the HTML page and see what happens:

    function checkDL()

    {

    var str = "SMITH707173HK9GP";

    var m;

    alert(str);

    if ((m = re.exec(str)) !== null) {

        if (m.index === re.lastIndex) {

            re.lastIndex++;

        }

        alert("Driver licence format correct");

    }

    else

    {

        alert("Invalid driver licence format. Please check your driving licence and enter the correct format.");

    }

    }

    call checkDL(); from the JavaScript window in Captivate.

    If it works you'll the need to pass in an argument.

    gubhare
    gubhareAuthor
    Participating Frequently
    May 5, 2015

    Hi,

    Good morning.

    Thanks for your reply. I did try executing it through a function but the results are the same. Even though the format is correct it still says invalid format.

    Any other clues?

    Thanks

    Ganesh

    TLCMediaDesign
    Inspiring
    May 5, 2015

    I just ran this script in an html page with the function called from the onload and it worked fine.

    <script>

    var re = /^(?=.{16}$)[A-Za-z]{1,5}9{0,4}[0-9](?:[05][1-9]|[16][0-2])(?:[0][1-9]|[12][0-9]|3[01])[0-9](?:99|[A-Za-z][A-Za-z9])(?![IOQYZioqyz01_])\w[A-Za-z]{2}/;

    function checkDL()

    {

    var str = "SMITH707173HK9GP";

    var m;


    if ((m = re.exec(str)) !== null) {

        if (m.index === re.lastIndex) {

            re.lastIndex++;

        }

        alert("Driver licence format correct");

    }

    else

    {

        alert("Invalid driver licence format. Please check your driving licence and enter the correct format.");

    }

    }

    </script>