Validator

About this task

Only the Text and Password widgets need the validator. There are two types of validator, Before-Validator and After-Validator. See the following table for details:

Table 1.
Widget Injection Injection description Sample in UI.xui
Text beforeValidators When user start to input, beforeValidators will run. If validation failed, the input will be ineffective.
<Text background="240,0,0">
 <list Injection="beforeValidators">
  <com.ibm.btt.sample.xui.AccNumberValidator/>
 </list>
</Text>
afterValidators When user input finished and lost the focus status for the text widget, the afterValidators will run. If validation failed, the error system will display the information about it.
<Text background="240,0,0">
 <list Injection="afterValidators"> 
  <com.ibm.btt.sample.xui.AccNumberValidator/> 	 
 </list>
</Text>
Password beforeValidators When user input, beforeValidators will run. If validation failed, the input will be ineffective.
<Password background="240,0,0"> 
 <list Injection="beforeValidators"> 
	<com.ibm.btt.sample.xui.AccNumberValidator/>
 </list> 
</Password >
afterValidators When user input finished and lost the focus status for the text widget, the afterValidators will run. If validation failed, the error system will display the information about it.
<Password background="240,0,0"> 
 <list Injection="afterValidators"> 
  <com.ibm.btt.sample.xui.AccNumberValidator/>
 </list> 
</Password >

Prebuilt Validator

XUI engine also provide some prebuilt validator. See the following table for details:

Table 2.
Validator Description
AlphaNumericValidator The input can only be number and alpha. It can be used in afterValidators and beforeValidators;
NumericValidator The input can only be number. When the input is not a valid alphabet character, it will be ineffective. It can be used in afterValidators and beforeValidators.
NumberPatternValidator The input can only be as the pattern specified. This format of the pattern is ‘##-##-##'. The ‘#' stands for a number.
MinLengthValidator Using this you can specify the minimal length of text input. It's usually used in afterValidators.
MaxLengthValidator Using this you can specify the maximum length of text input. It can be used in afterValidators and beforeValidators.
RegexValidator The input must match the regex which is specified by the regex property. It's usually used in afterValidators.
DateValidator The input can only be date. The format of the Date is specified by the format property. For example “yyyy/MM/dd”. It's usually used in afterValidators.
EmailAddrValidator The input can only be the email string.

To inject this function, you should create your own class.

The xui.xml file should be edited like one of the following sample codes.