SetValidate method (DataWindows)
Description
Sets the input validation rule for a column in a DataWindow
control or DataStore.
SetValidateByColNum
A separate method name is provided as an alternative syntax
for the Web DataWindow server component, which cannot use overloaded
methods.
Controls
|
DataWindow type |
Method applies to |
|---|---|
|
PowerBuilder |
DataWindow control, DataWindowChild object, DataStore |
|
Web |
Server component |
|
Web ActiveX |
DataWindow control, DataWindowChild object |
Syntax
[PowerBuilder]
|
1 |
integer <span>dwcontrol</span>.<span>SetValidate</span> ( string <span>column</span>, string <span>rule</span> )<br>integer <span>dwcontrol</span>.<span>SetValidate</span> ( integer <span>column</span>, string <span>rule</span> ) |
[Web DataWindow server component]
|
1 |
short <span>dwcontrol</span>.<span>SetValidate</span> ( string <span>column</span>, string <span>rule</span> )<br>short <span>dwcontrol</span>.<span>SetValidateByColNum</span> ( short <span>column</span>, string <span>rule</span> ) |
[Web ActiveX]
|
1 |
number <span>dwcontrol</span>.<span>SetValidate</span> ( string <span>column</span>, string <span>rule</span>) <br>number <span>dwcontrol</span>.<span>SetValidate</span> ( number <span>column</span>, string <span>rule</span>) |
|
Argument |
Description |
|---|---|
|
dwcontrol |
A reference to a DataWindow control, |
|
column |
The column for which you want to set |
|
rule |
A string whose value is the validation |
Return Values
Returns 1 if it succeeds and –1 if an error occurs.
If any argument’s value is null, in PowerBuilder and JavaScript
the method returns null.
Usage
Validation rules are boolean expressions that usually compare
the value in the column’s edit control to some other value.
When data the user enters fails to meet the criteria established
in the validation rule, an ItemError event occurs.
You can specify validation rules in the Database painter or
the DataWindow painter, and you can change the rules in scripts
using SetValidate. A validation rule can include
any DataWindow painter function. For more information, see the Users
Guide.
If you want to change a column’s validation rule
temporarily, you can use GetValidate to get and
save the current rule. To include the value the user entered in
the validation rule, use the GetText method.
You can compare its return value to the validation criteria.
If the validation rule contains numbers, the DataWindow expects
the numbers in U.S. format. In PowerBuilder, be aware that the String function formats
numbers using the current system settings. If you use it to build the
rule, specify a display format that produces U.S. notation.
Examples
The following assigns a validation rule to the current
column in dw_employee. The rule ensures that the data entered
is greater than zero:
|
1 |
dw_employee.<span>SetValidate</span>(dw_employee.GetColumn(), & |
|
1 |
"Number(GetText( )) > 0") |
The following assigns a validation rule to the current
column in dw_employee. The rule checks that the value entered
is less than the value in the Full_Price column:
|
1 |
dw_employee.<span>SetValidate</span>(dw_employee.GetColumn(), & |
|
1 |
"Number(GetText( )) < Full_Price") |
This example defines a new validation rule for the
column emp_state in the DataWindow control dw_employee.
The new rule is [A-Z]+ , meaning the
data in emp_state must be all uppercase characters. The
text pattern must be enclosed in quotes within the quoted validation
rule. The embedded quotes are specified with ~”. The script saves
the old rule, assigns the new rule, performs some processing, and
then sets the validation rule back to the old rule:
|
1 |
string OldRule, NewRule |
|
1 |
|
1 |
NewRule = "Match(GetText(), ~"[A-Z]+~")" |
|
1 |
|
1 |
OldRule = dw_employee.GetValidate("emp_state") |
|
1 |
|
1 |
dw_employee.<span>SetValidate</span>("emp_state", NewRule) |
|
1 |
... //Process data using the new rule. |
|
1 |
|
1 |
// Set the validation rule back to the old rule. |
|
1 |
dw_employee.<span>SetValidate</span>("emp_state", OldRule) |