This function can be used in AutoPlay Media Studio 5.0 Professional to perform some simple data validation on an input object. You can use it to test the object's contents for the following criteria:
This function also demonstrates a naming technique that lets you create "categorized" functions that resemble the built-in actions in AutoPlay. You simply create a table and then define the function as an item in that table. (This is in fact how the built-in actions are done, although with some extra behind-the-scenes autocomplete and quickhelp magic.)
- minimum length (at least x characters)
- maximum length (no more than x characters)
- numeric characters only (no letters allowed)
Here is a short example demonstrating how you might call the function. Insert this example code in the On Click event for an object on a page that has an input object named "Input1" on it.Code:-- create the InputTest table if it doesn't already exist if not InputTest then InputTest = {}; end --[[ Function: InputTest.Validate Purpose: Perform some simple validation on an input object. Arguments: (string) ObjectName - The name of the object you want to test. (number) nMinChars - The minimum number of characters required. (number) nMaxChars - The maximum number of characters allowed. (nil for no limit) (boolean) bNumbersOnly - true if only numeric characters are allowed. Returns: true if the edit field is meets the criteria, false if it doesn't. --]] function InputTest.Validate(ObjectName, nMinChars, nMaxChars, bNumbersOnly) local strText = Input.GetText(ObjectName); local nLen = String.Length(strText); if(nLen < nMinChars) then return false; end if( (nMaxChars ~= nil) and (nLen > nMaxChars)) then return false; end if(bNumbersOnly) then -- does the string consist only of valid numeric characters? if(String.TrimRight(strText, "1234567890-.") ~= "") then return false; end end return true; end
Note that the function's second and third parameters are optional...you can test for only a minimum of 3 characters (with no maximum and alphanumeric characters okay) with the following call:Code:if(InputTest.Validate("Input1", 3, 5, true)) then Dialog.Message("HK-47 says:","Observation: Well done, Master! Your response passes my expert validation protocols."); else Dialog.Message("HK-47 says:","Warning: Incorrect response.\r\n\r\nResolution: Enter a number between 3 and 5 digits long."); end
Requirements:Code:if(InputTest.Validate("Input1", 3)) then -- test passed end
Note: this function will only work with AutoPlay Media Studio 5.0 Professional Edition, since the Standard Edition does not have an input object.

