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
Name | Description | Datatype | Default |
---|---|---|---|
required | When set to true , the component must have a value before the form can be submitted via a button. | Boolean | False |
minLength | Checks the minimum length for text input. | Integer | |
maxLength | Checks the maximum length for text input. | Integer | |
minWords | Checks the minimum number of words for text input. | Integer | |
maxWords | Checks the maximum number of words for text input. | Integer | |
pattern | Checks the text input against a regular expression pattern. | String | |
custom | A custom JavaScript based validation. See section Custom JavaScript. | String | |
json | Custom validation specified using JSON logic. | Json | |
customMessage | Specify a custom message to be displayed when the validation fails. | String | |
min | For Number components, the minimum value. | Double | |
max | For Number components, the maximum value. | Double | |
step | For Number components, the granularity of the input value. | Double | |
integer | For 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'