CHKFMT: Checking the Format of a String

How to:

The CHKFMT function checks a character string for incorrect characters or character types. It compares each character string to a second string, called a mask, by comparing each character in the first string to the corresponding character in the mask. If all characters in the character string match the characters or character types in the mask, CHKFMT returns the value 0. Otherwise, CHKFMT returns a value equal to the position of the first character in the character string not matching the mask.

If the mask is shorter than the character string, the function checks only the portion of the character string corresponding to the mask. For example, if you are using a four-character mask to test a nine-character string, only the first four characters in the string are checked; the rest are returned as a no match with CHKFMT giving the first non-matching position as the result.


Top of page

x
Syntax: How to Check the Format of a Character String
CHKFMT(numchar, source_string, 'mask', output)

where:

numchar

Integer

Is the number of characters being compared to the mask.

string

Alphanumeric

Is the character string to be checked.

'mask'

Alphanumeric

Is the mask, which contains the comparison characters enclosed in single quotation marks.

Some characters in the mask are generic and represent character types. If a character in the string is compared to one of these characters and is the same type, it matches. Generic characters are:

A is any letter between A and Z (uppercase or lowercase).

9 is any digit between 0–9.

X is any letter between A–Z or any digit between 0-9.

$ is any character.

Any other character in the mask represents only that character. For example, if the third character in the mask is B, the third character in the string must be B to match.

output

Integer



Example: Checking the Format of a Field

CHKFMT examines EMP_ID for nine numeric characters starting with 11 and stores the result in a column with the format I3.

CHKFMT(9, EMP_ID, '119999999', 'I3')

For 071382660, the result is 1.

For 119265415, the result is 0.

For 23764317, the result is 2.


iWay Software