cognos.Prompt.Control.setValidator method

Changes the default validation function for a control to one defined by the user.

When the specified function returns false, the UI element associated with the control indicates that a validation error occurred. When used in a multi-select control, the Insert button is disabled.

Note: Date and date & time prompt controls do not support this method.

Syntax

{void} setValidator(oFct)

Parameters

{function} oFct
A user-defined function that takes the user input as a parameter and returns a Boolean value.

Returns

{void}

Example

This example demonstrates how to ensure that a valid postal code is provided in the form A1A 1A1.

textBox.setValidator(
	function (values) {
		var result = false;
		if (values && values.length > 0) {
			var sValue = values[0]['use'];
			var rePostalCodeFormat = new RegExp( "[a-z][0-9][a-z] ?[0-9][a-z][0-9]", "gi" );
			if ( rePostalCodeFormat.test(sValue ) ) {
				result=true;
			}
		}
		return result;
	}
);