Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

regex javascript not working in Captivate8 but works fine in CP6

New Here ,
May 04, 2015 May 04, 2015

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

1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 04, 2015 May 04, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 05, 2015 May 05, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 05, 2015 May 05, 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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 05, 2015 May 05, 2015

Hi,

Thanks once again for getting back quickly. It seems to work in all other systems except Captivate8. It even works in Captivate6.


So it must  be a bug within captivate8. I want the Adobe technical/product support to look into the matter, however I am not sure what is the proper channel to report this to Adobe technical/product support?


Whome should I contact?


Can anyone please guide me.


Thanks

Ganesh



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 05, 2015 May 05, 2015

What are you publishing, HTML5, SWF or both?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 27, 2017 Mar 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!!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 27, 2017 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 27, 2017 Mar 27, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 27, 2017 Mar 27, 2017

Not a good idea, that window (it is the same in advanced actions) has too much limitations, is not intended for such complicated scripts. Add it in the JS file that accompanies the published file or in separate JS file which you call.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 27, 2017 Mar 27, 2017

when I open

CPM.js

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 CPT9 have some issue with \ in REGEX

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 27, 2017 Mar 27, 2017

Regex is not the only thing it has trouble with. But I'd say it generally does a pretty good job considering that the entire script needs to be programmatically turned into a string to pass as an argument.

You really should execute your script outside of CP, either in the head of the HTML or in an included JS file.

There are plenty of examples on how to set this up on this forum, although the search can be a little finicky.

Put a js file here:

C:\Program Files\Adobe\Adobe Captivate 9 x64\HTML\assets\js\

Put an JS include to that file in the index.html here:

C:\Program Files\Adobe\Adobe Captivate 9 x64\HTML\

You can then just keep adding script to the js file and the scripts will be there when you preview in the browser of publish.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 27, 2017 Mar 27, 2017

I  followed your advice:

I created a function in the head of Captivate index.html ,  just after the function initializeCP() { ... }  :

function regex_email()

{

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

  }

}

and I just inserted a call of the function in Conditional Action , Execute Javascript, Javascript Window :

regex_email();

Now it works fine ! !

Thank you very much !

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 28, 2017 Mar 28, 2017

Hello, I tried the second method with external  assets/js/regex.js file.

Within the index.html, which one is it the better way to call the javascript file? (I tried each one and it works perfectly)

in the head ?

Voila_Capture 2017-03-28_04-53-51_PM.png

or

in the script.onload function?

Voila_Capture 2017-03-28_04-55-20_PM.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 28, 2017 Mar 28, 2017

I'm not sure it really matters that much.

I put mine in the head.

You are obviously showing that post publish as the index.html template file has a variable placeholder like:

var lJSFiles = [ @JSFILES_ARRAY ];

I don't want to insert something there, so I use the head.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 28, 2017 Mar 28, 2017

If I don't want the REGEX formula to be viewed by the user (when viewing the page code),

does I absolutely need a PHP page with the regex formula to validate the entry, using POST technique with AJAX to transmit the data?

Is there another way?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 28, 2017 Mar 28, 2017
LATEST

Why would you care if the user saw it?

You can obfuscate it multiple time by different obfuscators if you want.

Else it would need to be server side.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources