Field ValRule

Field ValRule

Welcome to our Knowledge Base

Documentation | Blog | Demos | Support

< All Topics
Print

Field ValRule

The validation rule for a form field.

Entry fields: Sets out a validation rule against which data entered into an entry form field is to be tested.

Toggle form fields or menu items: Sets out a validation rule which activates the “on” state of the field or item if its value is valid.

Valid Values

A 256-character string, containing the validation rule

Remarks

The format of the validation rule depends on the data type (DT) of the form field. For more information, see the discussion below.

HOW TO USE THE “VALIDATION RULE” ATTRIBUTE

Zim uses the validation rule to check that all data entered into the form field conforms to a pre-determined pattern. How a validation rule is constructed depends on whether the form field’s data type is alphanumeric, non-digit, date, or numeric/calculator.

Alphanumeric/Non-Digit Validation Rules

Table below shows how to construct a validation rule for an alphanumeric or non-digit form field. The next table shows some examples of validation rules, together with some legal and illegal data values for each.

How to Construct Validation Rules for Alphanumeric or Non-Digit Form Fields

CHARACTER CODE

APPLICATION

Pattern Matching

A

Can be replaced by any letter (A to Z, a to z).

X

Can be replaced by any letter or digit (A to Z, a to z, 0 to 9).

9

Can be replaced by any digit (0 to 9).

Z

Can be replaced by any digit or blank (0 to 9, and space character).

Any other character or digit in a pattern must be replaced by the identical character or digit. The “escape” character (backslash–) can be used in front of any of the above characters when you want to use that character literally (i.e., to use the Z as the letter “Z” instead of as a pattern matching symbol for blanks and digits).

CHARACTER CODE

APPLICATION

Syntax

[ ]

Encloses a set of alternate characters. (Note: all characters used inside square brackets are taken literally, that is “A” is the letter A, not the pattern matching symbol “A” used to indicate any letter.)

Used inside square brackets (“[” and “]”) to denote a range of characters, for example, [B-F] would mean any of B, C, D, E, or F.

|

The “or” bar separates alternative validation patterns, for example, C|D would mean either C or D.

 

An Alphanumeric Validation Example: Telephone Numbers

A good example of the flexibility of the “validation rule” attribute is the validation of North American telephone numbers. The telephone numbers may or may not have a preceding area code. Suppose that telephone numbers have the property that the first digit of an area code may only be between 2 and 9. The second digit may only be a 0 or a 1 and the first and second digit of the exchange number may only be between 2 and 9.

When defining an alphanumeric form field to hold such a telephone number, the alphanumeric validation rule is a combination of two patterns:

[2-9][0-1]9-[2-9][2-9]9-9999|[2-9][2-9]9-9999

therefore:

212-643-9763    is legal from first pattern.

222-643-9763    is illegal.

643-9763        is legal from second pattern.

143-9763        is illegal.

Numeric/Calculator Validation Rules

Table below shows how to construct validation rules for numeric or calculator form fields. Next table  shows some examples of numeric validation rules, explaining the values that are legal for each.

Date Validation Rules

Form fields of data type date may be assigned a validation rule that describes the acceptable range of dates. The format of the validation pattern is the same as that used for numeric form fields, but the numbers must be legitimate date values. For example, the rule:

19920101-19921231

means that any date in the year 1992 is acceptable.

Examples of Alphanumeric Validation Patterns

VALIDATION RULE

LEGAL VALUES

ILLEGAL VALUES

AB

qB

q”

 

AB

q

 

LB

7B

 

BB

B8

XX-XXXX

AL-9632

$63.09

Q[L-P]A

QLA

QRA

 

QMA

qLa

 

QPA

QPB

[ACEG]

A

B

 

C

D

 

E

F

[Ax-zB]

A

a

 

y

Y

 

B

b

A|9

m

?

 

3

$

 

Q

%

Y|N

Y

A

 

N

5

 

How to Construct Validation Rules for Numeric Form Fields

RULES FOR CREATING NUMERIC VALIDATION RULE PATTERNS

1.  The pattern may specify one or more numbers, or ranges of numbers, that the value in the form field must satisfy.

2.  Numbers may include digits (0-9), the decimal point, and the plus (+) and minus (-) signs (e.g., -12, 2.141).

3.  Ranges are two numbers linked by a hyphen (e.g., 1-9, 1.45-1.46).

4.  Numbers and ranges may be specified together. Use the logical “or” bar (|) to separate one item from the next (e.g., 1|2|5-9).

Examples of Numeric Validation Patterns

VALIDATION RULE

MEANING

1|2|3|5

The only legal values that may be entered are 1, 2, 3, or 5.

10-20

Legal values range from 10 to 20 inclusive. 10.123 is also a legal value.

10-20|100-200

Legal values lie in the range of 10 to 20 or 100 to 200.

-30–5|1|1.3-1.7

Legal values are between -30 and -5, or 1, or between 1.3 and 1.7.

FThe DataMask attribute can be used to control the number of decimal places allowed in a numeric or calculator form field.

Using a Validation Rule to Switch a Toggle Form Field “On”

In the absence of a ValRule, a toggle form field is set to the “on” state whenever its current data value exactly matches its WdgOnValue. However, by setting a ValRule, you can provide many alternative values for the “on” state.

Consider Figure 3.1.

Enter favorite food: ice cream

Figure 3.1: Setting a toggle button with a validation rule.

The end-user has typed “ice cream” into the entry field. (Assume that the field forces lowercase input, because validation rules are case-sensitive.) Also assume that the application program assigns “ice cream” to the option button box and executes a FORM DISPLAY command. The option button box checks “ice cream” against the ValRules of its option buttons; the “Dairy” button is therefore set “on”, and all other buttons, “off”.

See Also

DataMask, DT, FT, VA, VR, WdgInputMask, WdgOnValid Values

Was this article helpful?
0 out of 5 stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.

Leave a Reply

Your email address will not be published. Required fields are marked *

en_CAEnglish