Requires Platform 4.5+
Supplied Validators
This documet describes the use of the following supplied validators:
Validator | Description |
requiredFieldValidator | Validates whether a field contains a value. |
stringLengthValidator | Validates whether a field contains a value within the specified length range. This validates based on amount of data entered. |
integerValidator | Validates whether a field contains valid whole numbers (integers). |
decimalValidator | Validates whether a field contains valid decimal or floating point numbers. |
rangeValidator | Validates whether a field contains the specified range of integers or decimal numbers. This validates based on actual values of data entered. |
dateValidator | Validates whether a field contains a value in the specified date format. |
currencyValidator | Validates whether a field contains a valid currency amount according to a specified locale. |
validatorChain | Specifies a series of validators to run on one |
Common Attributes
All supplied validators provide the following common attributes:
...
このドキュメントでは、用意されている次のバリデータの使用方法について説明します。
バリデータ | 説明 |
requiredFieldValidator | フィールドに値が含まれているかどうかを検証します。 |
stringLengthValidator | フィールドに指定した範囲の長さの値が含まれているかどうかを検証します。この検証は、入力されたデータの量に基づいて行われます。 |
integerValidator | フィールドに有効な整数が含まれているかどうかを検証します。 |
decimalValidator | フィールドに有効な 10 進数または浮動小数点数が含まれているかどうかを検証します。 |
rangeValidator | フィールドに指定した範囲の整数または 10 進数が含まれているかどうかを検証します。この検証は、入力されたデータの実際の値に基づいて行われます。 |
dateValidator | フィールドに指定した日付フォーマットの値が含まれているかどうかを検証します。 |
currencyValidator | フィールドに指定したロケールに基づく有効な通貨金額が含まれているかどうかを検証します。 |
validatorChain | 一度に実行する一連のバリデータを指定します。 |
共通属性
用意されているバリデータは、いずれも次の共通属性を持っています。
...
バリデータ タグ要素 | 説明 |
id=“passwordValidator” | 特定のバリデータ タイプの特定のインスタンスに一意の ID を指定します。 |
value=“password.text” | UI ファイルの textFieldまたは passwordFieldの ID と、そのフィールドの検証対象の text属性を指定します。 |
onSuccess=“mco://myMco.validPassword()” | Specifies the MCO to run - for example, to display a success message - upon successful validation. 検証が成功したときに実行する MCO (たとえば、成功のメッセージを表示する) を指定します。 |
onFailure=“mco://myMco.invalidPassword()” | Specifies the MCO to run - for example, to display a failed message - upon unsuccessful validation. |
For example:
Validator Declaration
...
検証が成功しなかったときに実行する MCO (たとえば、失敗のメッセージを表示する) を指定します。 |
例:
バリデータ宣言
Code Block |
---|
<validator:requiredFieldValidator
xmlns="http://nexaweb.com/validator"
id="usernameValidator"
value="username.text"
onSuccess="macro://success.execute()"
onFailure="macro://failure.execute()" /> |
...
...
検証する要素
<textField
...
...
...
...
In addition to the attributes common to all validators, the stringLengthValidator provides the following attributes:
...
属性 | 説明 |
maximum = | Maximum number of characters a field can contain. フィールドに含めることができる最大文字数です。 |
minimum = | Minimum number of characters a field can contain. |
Maximum and minimum values include the value specified.
You can use an open ended range by specifying only a maximum or minimum value.
If you do not specify a minimum or maximum value, the element on which you invoke the validator accepts data of any length.
For example:
The following stringLengthValidator validates a string from 8 to 15 characters in length.
Validator Declaration
...
language | html/xml |
---|---|
linenumbers | true |
フィールドに含めることができる最小文字数です。 |
maximum と minimum には、指定した値が含まれます。
maximum または minimum のどちらか一方のみを指定することにより、最小値または最大値に制限のない値を使用できます。
maximum または minimum を指定しない場合、バリデータを呼び出した要素では、データの長さが任意となります。
例:
次の stringLengthValidator では、長さが 8 ~ 15 文字の文字列を検証します。
バリデータ宣言
Code Block |
---|
<validator:stringLengthValidator
xmlns |
...
= |
...
“http://nexaweb.com/ |
...
validator” id= |
...
“passwordValidator” value= |
...
“password. |
...
text” minimum= |
...
“8” maximum= |
...
“15” onSuccess= |
...
“mco://myMco.validPassword() |
...
” onFailure= |
...
“mco://myMco.invalidPassword() |
...
” /> |
...
...
検証する要素
<passwordField
...
...
...
...
minimum
...
Specify a maximum attribute value of 8 to create an open-ended range of no more than 8 characters.
Specify minimum and maximim values of 8 to validate for a value length of exactly 8 characters.
rangeValidator
In addition to the attributes common to all validators, the rangeValidator provides the following attributes:
...
maximum 属性の値として 8 を指定すると、8 文字以下で最小文字数が無制限の範囲が作成されます。
minimum 属性および maximim 属性の値として 8 を指定すると、長さが 8 文字ちょうどである値が検証されます。
rangeValidator
rangeValidatorは、すべてのバリデータに共通する属性に加えて、次の属性を持っています。
属性 | 説明 |
locale | 数値のフォーマット設定で使用するロケールを指定します。ロケール値は、「言語コード_国コード」のフォーマットで指定します。 for a full list of language codes. Default value is en or English.言語については、ISO-639 で定義されている小文字 2 文字のコードを使用します。すべての言語コードの一覧については、http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt For country, use a 2-character upper case code as defined by ISO-3166. See を参照してください。デフォルトは en(英語) です。 for A full list of codes. Default value is US or United States.国については、ISO-3166 で定義されている大文字 2 文字のコードを使用します。すべてのコードの一覧については、http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html |
maximum | Maximum interger or decimal number the field can contain. |
minimum | Minimum interger or decimal number the field can contain. |
format | Use for ranges of floating point numbers to specify the precision of real numbers. Format must conform to the java.text.DecimalFormat format styles. If you do not specify a format for floating point numbers, validation might result in unexpected behavior. |
Maximum and minimum values include the value specified.
You can use an open ended range by specifying only a maximum or minimum value.
For example:
Validator Declaration
...
language | html/xml |
---|---|
linenumbers | true |
...
を参照してください。デフォルトは US(米国) です。 | |
maximum | フィールドに含めることができる整数または 10 進数の最大値です。 |
minimum | フィールドに含めることができる整数または 10 進数の最小値です。 |
format | 浮 動小数点数の範囲について、実数の精度を指定するために使用します。フォーマットは java.text.DecimalFormat のフォーマットスタイルに従う必要があります。浮動小数点数のフォーマットを指定しない場合、バリデータは予期せぬ動作を示すことがあります。 |
maximum と minimum には、指定した値が含まれます。
maximum または minimum のどちらか一方のみを指定することにより、最小値または最大値に制限のない値を使用できます。
例:
バリデータ宣言
Code Block |
---|
<validator:rangeValidator xmlns=“http://nexaweb.com/ |
...
validator” id= |
...
“weightValidator” value= |
...
“weight. |
...
text” minimum= |
...
“2. |
...
5” maximum= |
...
“5. |
...
8” format="0.0" locale="en_US" onSuccess= |
...
“mco://myMco.validWeight() |
...
” onFailure= |
...
“mco://myMco.invalidWeight() |
...
” /> |
...
検証する要素
<textField
...
...
...
dateValidator
In addition to the attributes common to all validators, the dateValidator provides the following attributes:
属性 | 説明 |
format A | valid 許容可能な日付フォーマットを定義する、有効な java.text.SimpleDate format style to define acceptable date format.フォーマット スタイルです。 |
locale | Specifies the locale to use in date formatting. Specify locale value in language-code_country-code format. For language, use a 2-character lower case code as defined by ISO-639. See 日付のフォーマット設定で使用するロケールを指定します。ロケール値は、「言語コード_国コード」のフォーマットで指定します。 for a full list of language codes. Default value is en or English.言語については、ISO-639 で定義されている小文字 2 文字のコードを使用します。すべての言語コードの一覧については、http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt For country, use a 2-character upper case code as defined by ISO-3166. See を参照してください。デフォルトは en (英語) です。 for A full list of codes. Default value is US or United States.国については、ISO-3166 で定義されている大文字 2 文字のコードを使用します。すべてのコードの一覧については、http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html |
For example:
Validator Declaration
...
language | html/xml |
---|---|
linenumbers | true |
...
を参照してください。デフォルトは US (米国) です。 |
例:
バリデータ宣言
Code Block |
---|
<validator:dateValidator xmlns= |
...
“http://nexaweb.com/ |
...
validator” id= |
...
“birthValidator” value= |
...
“birthdate. |
...
text” |
...
format="yyyy/MM/dd"
locale="es_ES"
onSuccess= |
...
“mco://myMco.validBirthdate() |
...
” onFailure= |
...
“mco://myMco.invalidBirthdate() |
...
” /> |
...
<textField
...
...
...
currencyValidator
In addition to the attributes common to all validators, the currencyValidator provides the following attributes:
...
属性 | 説明 |
locale | 通貨のフォーマット設定で使用するロケールを指定します。ロケール値は、「言語コード_国コード」のフォーマットで指定します。 for a full list of language codes. Default value is en or English.言語については、ISO-639 で定義されている小文字 2 文字のコードを使用します。すべての言語コードの一覧については、http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt For country, use a 2-character upper case code as defined by ISO-3166. See を参照してください。デフォルトは en (英語) です。 for A full list of codes. Default value is US or United States.国については、ISO-3166 で定義されている大文字 2 文字のコードを使用します。すべてのコードの一覧については、http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html |
prefix | Specifies a prefix that must appear for any input values. For example, $ |
Example
Validator Declaration
...
language | html/xml |
---|---|
linenumbers | true |
を参照してください。デフォルトは US (米国) です。 | |
prefix | すべての入力値に含まれている必要があるプレフィックスを指定します。たとえば、$ を指定します。 |
例:
バリデータ宣言
Code Block |
---|
<validator:dateValidator
xmlns |
...
= |
...
“http://nexaweb.com/ |
...
validator” id= |
...
“totalValidator” value= |
...
“total. |
...
text” prefix= |
...
“¥” locale="ja_JP" onSuccess= |
...
“mco://myMco.validTotal() |
...
” onFailure= |
...
“mco://myMco.invalidTotal() |
...
” / |
...
> |
Element to Validate
...
<textField id=
...
...
Validator Chain
You can create a validatorChain to run a series of validators on the same or different fields in a UI file.
The validatorChain provides a failFast boolean attribute, which when set to true, causes the validator chain to stop executing as soon as any validator fails. You can specify onSuccess and onFailure behaviors for the chain in addition to setting these for each validator included in the chain. The chain succeeds if all the validators within it succeed.
If you set onSuccess and onFailure behaviors for the chain in addition to any or all of the validator included in the chain, users can potentially see messages for the success or failure of each validator in addition to seeing messages for the success or failure of the chain.
You can include in a validatorChain a:
- Previously declared validator
- Validator declared for first time in chain
- Validator reference.
The validatorChain element tag includes the following attributes:
...
language | html/xml |
---|---|
linenumbers | true |
...
UI ファイルの同じフィールドまたは異なるフィールドで一連のバリデータを実行する validatorChainを作成できます。
validatorChainは、ブール型の failFast 属性を持っています。この属性を true に設定すると、いずれかのバリデータが検証に失敗したときに、バリデータチェーンの実行が停止します。チェーンに含まれている各バリデータの onSuccess 動作とonFailure 動作を設定することに加えて、チェーンの onSuccess 動作と onFailure 動作を指定することもできます。チェーンは、チェーン内のすべてのバリデータが成功した場合に成功します。
チェーンに含まれるいずれかのバリデータまたはすべてのバリデータの onSuccess 動作および onFailure 動作に加えて、チェーンの onSuccess 動作および onFailure 動作も設定した場合、ユーザーにはチェーンの成功または失敗のメッセージだけでなく、各バリデータの成功または失敗のメッセージも表示される可能性があります。
validatorChainには次のものを含めることができます。
- あらかじめ宣言済みのバリデータ
- チェーン内で初めて宣言したバリデータ
- バリデータ参照
Code Block |
---|
<validator:validatorChain xmlns:val=http://nexaweb.com/validator id= |
...
“loginValidator” onSuccess= |
...
“mco://myMco.login() |
...
” onFailure= |
...
“macro://failure.execute( |
...
‘invalid username and or |
...
password’) |
...
” failFast= > <validator:Validator /> <validator:validatorReference |
...
/>
</validator:validatorChain> |
...
The following table provides descriptions of the validatorChain attributes:
...
バリデータ タグ要素 | 説明 | ||
Opening tag of a validator chain. | バリデータ チェーンの開始タグです。 | ||
id=“ ” | Specifies a unique ID for this validator chain. 特定のバリデータ チェーンに一意の ID を指定します。 | ||
onSuccess=“ ” | Specifies the MCO or Macro to run - for example, to display a success message - upon successful completion of all of the validators in the chain. チェーン内のすべてのバリデータの検証が成功したときに実行する MCO またはマクロ (たとえば、成功のメッセージを表示する) を指定します。 | ||
onFailure=“ ” | Specifies the MCO or Marco to run - for example, to display a failed message - upon failure of any validator in the chain. | failFast= | Specifies whether to stop execution of the chain upon failure of any validator within the chain. Set this attribute to change from default only. Default=true. If set to false, validator chain continues to execute until all validators within the chain execute no matter the result of any single validator in the chain. チェーン内のいずれかのバリデータの検証が失敗したときに実行する MCO またはマクロ (たとえば、失敗のメッセージを表示する) を指定します。 |
failFast= | チェー ン内のいずれかのバリデータの検証が失敗したときに、チェーンの実行を停止するかどうかを指定します。この属性は、デフォルトから変更する場合にのみ設定 します。デフォルトは true です。この属性を false に設定すると、バリデータ チェーンはチェーン内のいずれかのバリデータの結果に関係なく、チェーン内のすべてのバリデータが実行されるまで、実行を継続します。 | ||
<validator:Validator / > or <validator:validatorReference > または <validator:validatorReference /> | Specifies each validator or reference to a validator to include in the chain. チェーン内に含める各バリデータまたはバリデータ参照を指定します。 | ||
validatorChain> | Closing tag of a validator chain. |
Example:
Validator Declaration
...
language | html/xml |
---|---|
linenumbers | true |
...
バリデータ チェーンの終了タグです。 |
例:
Code Block |
---|
<validator:requiredFieldValidator xmlns:validator="http://nexaweb.com/validator" |
...
id="passwordRequiredValidator" |
...
|
...
value="password.text"
|
...
onSuccess=""
|
...
onFailure="macro://failureMacro.execute('Password required')" /> |
...
|
...
...
バリデータチェーン宣言
...
language | html/xml |
---|---|
linenumbers | true |
...
Code Block |
---|
<validator:validatorChain xmlns:validator="http://nexaweb.com/validator"> |
...
id="myValidator">
|
...
<validator:validatorReference validator="passwordRequiredValidator" /> |
...
<validator:stringLengthValidator |
...
value="password.text" |
...
minimum="8" |
...
|
...
maximum="20" |
...
onSuccess="mco://myMco.login()" onFailure="macro://failureMacro.execute( |
...
|
...
'Password must be between 8 and 20 character')" />
|
...
</validator:validatorChain> |
Element to Validate
...
language | html/xml |
---|---|
linenumbers | true |
...
バリデートする要素
<textField id="password"
...
...
text=""
...
onTextChange="validator://myValidator.execute()" />
In this example, the validatorChain, myValidator, includes two validators: the passwordRequiredValidator, declared outside of the chain and specified by reference; and the stringLengthValidator, declared inside the chain only.
Validator Reference
You can reference a previously declared validator in a validatorChain using a validator reference as a shorcut syntax.
The validatorReference tag element appears as follows
...
language | html/xml |
---|---|
linenumbers | true |
この例では、validatorChain, myValidatorは2つのバリデータを含んでいます。: passwordRequiredValidator, はチェーン外で宣言し、レファレンスにより特定されます。stringLengthValidatorはチェーン内でのみ、宣言されます。
バリデータレファレンス
Shortcut syntaxとして、validator referenceを使用し、validator chainで以前宣言されたvalidatorを参照することができます。
validatorReference tag要素は以下のように表現されます :
<validator:validatorReference xmlns:validator="http://nexaweb.com/validator" validator="usernameValidator" /
...
>
次の表はvalidatorReference 属性の説明を提供しています :
Validator |
...
タグ 要素 |
...
説明 |
...
...
Validator referenceのタグを開く |
validator=“ ” |
...
この UI で宣言されるバリデータの ID を特定する |