Can you check if a text entry box has an 'incorrect' character?

Apr 11, 2017

I'm currently rebuilding an online UI for some systems training.

We're using a time entry system, which only allows you to enter your time in the following formats:

0900
09:00

If anything else is entered into the fields, the system won't allow it.

Is there a way for me to build in detection so that when anything is entered into the text entry box, EXCEPT a number or a colon, it runs a trigger (i.e. to tell them they got it wrong)?

Thanks in advance!

5 Replies
James Bedwell
Wendy Farmer

Hi James

see if the attached sample file helps.

Thanks Wendy, but unfortunately that's not quite what I'm looking for.

I'm hoping to let the user type in whatever time they want - but then flag up an error if they've formatted the time incorrectly - i.e. if they've entered any other characters apart from a number or a colon.

Walt Hamilton

At the point you want to evaluate the entry, initiate a trigger to execute javascript. Start it like this:

var player = GetPlayer();
var text = player.GetVar("TextEntry");

Where TextEntry is the name in SL of the variable where you store their entry, and text is the variable js uses.

Then it's pretty easy in js to check if text contains any characters outside of 0-9 and :

If you don't know how, go to w3schools.com and click on learn Javascript. The advantage of this site is that they have a sandbox, where you can practice you script until it runs the way you want. Then copy it and put it into your trigger.

You end up passing the value back to SL with :

player.SetVar("result",testResult);

where result is the name of the variable in LS that catches the data, and testResult is the variable in js that contains the data to pass. You could pass a simple true or false, or you could get fancy and pass the illegal characters and report as "Please enter a time without using %result% in the time"

This discussion is closed. You can start a new discussion or contact Articulate Support.