TextEntry validation

How do I validate a text entry box when the field is required. The learner must complete a couple fields, some mandatory before clicking the next click action. On that click action, I want to validate that there is something in the field. Sometimes, I have to validate that it is an email address. All assistance is appreciated.



6 Replies
Michael Hinze

See attached a quick example with two text entry boxes and here is the published version:http://dev.keypointlearn.com/xcl71_SL/TEBContains/V4/story.html.

The first text entry box is checked whether or not it is empty. This is done with a simple 'not equal to (blank)' trigger. The email validation requires a JavaScript that checks if the entered string contains a "@" and a "." character. Hope that helps.

Mike Ramsey


Thank you for your support on this. Is it possible to do this action on a non test item slide? This is a simulation with over 300 slides and as many as five layers on some slides. Converting these to questions slides would not be conducive tot eh flow of the course.



Milton Edwards

Hi Michael, I could use help with the email validation for this Sign-In page. I want to validate the email address, as you did in your example, and I've tweaked with JavaScript, but I'm stuck. My code sample is below this form, but it's not working after I publish and test it in IE. The email textEntry field is called LrnrEmail.

Form

function validateForm()
var x = document.forms["thisForm"]["LrnrEmail"].value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
alert("Not a valid email address.");
return false;

<form name="thisForm" action="demo_form.asp" onsubmit="return" validateForm();" method="post">
<input type="text" name="LrnrEmail">
<input type="submit" value="Next">

I modified code from w3cschool and inserted this version into an Execute JavaScript trigger with the intent of validating the email address after the control loses focus and before the Learner clicks the Next button to advance to the quiz pages.

Would you mind sharing your JavaScript code as an example?

Thanks, in advance, for your help!

Milton Edwards

Hi Michael!
Thanks for sharing your .story file. I didn't see the file initially. I'm reviewing it to see what adjustments I need to make. I like your use of layer responses. Your script, however, looks nothing like the one I modified above; so I'll work from your example since yours works.


Christie Pollick

Hi, Milton -- Thanks for reaching out! As this discussion is dated and the last activity was a few years ago, it's possible that Michael is no longer subscribed to the post. As JavaScript is not something for which we can offer support, if you find that you have specific questions for Michael, you are welcome to reach out via the 'Contact Me' link on his profile page.