Validate

Most components are able to perform some validation of the values that are provided by the user of the app. The validation takes place in the browser window, before any submission data is sent to the backend. This makes the validation a very convenient method to give an early warning to the user that a provided value may be incorrect, without impacting performance of the application. However, for secure deployment of apps, it is required to also perform validation of user provided values in the backend before using them.

Validation can be configured using the Builder. Each component has a Validation tab that shows the available options.

Validation tab

To add validation programmatically, create a Validate object for the component and set its properties to define the validation criteria.

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. For more advanced custom messages, see the Error class.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 Password that has a validation on the minimum number of characters in the input.

Validate

The initialization code is as follows:

passwd = component.Password("passwd", form)
passwd.label = "Password"

validate = component_properties.Validate(passwd)
validate.required = True
validate.minLength = 8
validate.customMessage = "Password shall have at least 8 characters."

ok = component.Button("ok", form)
ok.label = "Ok"
ok.disableOnInvalid = True
passwd = component.Password("passwd", form);
passwd.label = "Password";

validate = componentProperties.Validate(passwd);
validate.required = true;
validate.minLength = 8;
validate.customMessage = "Password shall have at least 8 characters.";

ok = component.Button("ok", form);
ok.label = "Ok";
ok.disableOnInvalid = true;