Skip to main content
Participating Frequently
March 27, 2017
Question

Use of backslash with REGEX in JS Window or Conditional Actions in "Advanced action" .

  • March 27, 2017
  • 1 reply
  • 220 views

I have a issue  with  backslash \ character in REGEX verification test() !

in JS Window or Conditional Actions in "Advanced action" ( IF Then "Execute Javascript " Else )

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);

}

solution in this case: I replaced \d with its equivalent expression [0-9] and it works perfectly !

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

But with this another example:

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

Also, I replaced \w by its equivalent [a-zA-Z0-9_]

But there is a problem, Captivate sees 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....


Does anyone can help ?

How to Ask Adobe programmers to fix that BUG ?

    This topic has been closed for replies.

    1 reply

    darighAuthor
    Participating Frequently
    March 27, 2017

    Here is the CPM.js file that Captivate created with my second example....

    cp.runJavascript(\'var BC_email= window.cpAPIInterface.getVariableValue(\\\'v_BC_email\\\') ;\\nvar re = /^([a-zA-Z0-9_+-]+(\.[a-zA-Z0-9_+-]+)*)@([a-zA-Z0-9]+(-*[a-zA-Z0-9])+\.)+([a-zA-Z]{2,})$/g ;\\nif (re.test(BC_email)) {\\nwindow.cpAPIInterface.setVariableValue(\\\'v_Etat_email\\\',1);\\n} else {\\nwindow.cpAPIInterface.setVariableValue(\\\'v_Etat_email\\\',0);\\n}\',\'_self\');}else{window.v_Etat_email=cp.ho(\'0\');}\

    I can imagine why there are issues with backslash \ in REGEX