7 Replies
Alyssa Gomez

Hi Ronald,

It sounds like you not only want to limit the numeric entry field to six numbers, but you also want to ensure that all six numbers are entered, correct? 

That's not a default setting in Storyline, but you may be able to accomplish something like that using Javascript. We've got some savvy folks in this community who can certainly help with that. 🙂

Matthew Bibby

Ronald, this can be done and I'm happy to help you figure it out. 

But before digging in, I just wanted to check if there are any other requirements that you have?

For example, are the only acceptable characters 0 1 2 3 4 5 6 7 8 9? And am I correct in assuming that you'll want to trigger feedback if people have the less than (or more than) 6 numbers?

Ronald Anderson

Thanks Matthew. You are correct about acceptable characters and feedback. I am asking them to input their employee number, which is 6 characters and all numbers. I would like feedback to notify the learner to enter a valid employee number if they enter anything other than 6 numbers.

Matthew Bibby

Here you go Ronald.

See the demo here and grab the .story file from here

To set this up in your project, you'll need to create some text variables in Storyline called Length,  Number and EmployeeNumber (note that these are case-sensitive).

You'll need to make sure that your text entry field (where the person enters their employee number) is connected to the EmployeeNumber variable.

Then add an execute javascript trigger to the button that will be used to validate the text entry.

It should contain this JS:

var player = GetPlayer();
var id = player.GetVar("EmployeeNumber");
var number = !isNaN(id);
var length = id.length;

This will take the employee number from Storyline and check if it just contains numerical characters and how long it is.

It'll report this data back to Storyline via the Length and Number variables that we set up earlier. 

You can use this variable to drive your feedback via triggers like I've set up in the .story file:

(I know that trigger is a bit weird, it's that way to account for some of the oddities of JavaScript)

And then on the feedback layer:

Once this is set up it should show the feedback whenever the employee number is not a six digit number. Hope that helps. 

(Note, when testing JavaScript you'll either need to test the HTML5 output or upload your course to a web server / LMS in order for the code to work.)