Validate

Add a Validate object to a component to define custom validation for it. When the validation fails, the form cannot be submitted and an indication is given on why validation failed and where.

Properties

NameDescriptionDatatypeDefault
requiredWhen set to true, the component must have a value before the form can be submitted via a button.BooleanFalse
minLengthChecks the minimum length for text input.Integer
maxLengthChecks the maximum length for text input.Integer
minWordsChecks the minimum number of words for text input.Integer
maxWordsChecks the maximum number of words for text input.Integer
patternChecks the text input against a regular expression pattern.String
customA custom JavaScript based validation. See section Custom JavaScript.String
jsonCustom validation specified using JSON logic.Json
customMessageSpecify a custom message to be displayed when the validation fails.String
minFor Number components, the minimum value.Double
maxFor Number components, the maximum value.Double
stepFor Number components, the granularity of the input value.Double
integerFor Number components, whether or not the value must be a whole number.Boolean

Example

The following example shows a form with a TextField that has a validation on the maximum number of words in the input.

The initialization code is as follows:

tf          = component.TextField("LastName", form);
tf.label    = "Last name";

tfVal               = componentProperties.Validate(tf);
tfVal.maxWords      = 1;
tfVal.customMessage = "Last name shall be one word.";

btn         = component.Button("SubmitButton", form);
btn.action  = "submit";
btn.label   = "Submit";
tf = component.TextField('tf', form)
tf.label = 'Last name'

validate = component_properties.Validate(tf)
validate.maxWords = 1
validate.customMessage = 'Last name shall be one word.'

btn = component.Button('btn', form)
btn.action = 'submit'
btn.label = 'Submit'