Skip to content

UXValidationRule

UXValidationRule is one entry in a UXValidator’s list.

#use <UXKit> // or #import "UXValidator.xc"
class UXValidationRule : Object {
i32 type; // UXV_REQUIRED / UXV_REGEX / UXV_MINLEN / UXV_MAXLEN / UXV_INTRANGE
UXRegex* rx; // UXV_REGEX only
i32 a; // length, or range low
i32 b; // range high
u8* message; // what to show when this rule fails
}

The require* methods on the validator build these; you rarely construct one directly.

a and b mean different things per type. This avoids five separate classes:

typeabrx
UXV_REQUIRED
UXV_REGEXthe compiled pattern
UXV_MINLENminimum length
UXV_MAXLENmaximum length
UXV_INTRANGElowhigh

Both length rules use a as their single operand, so UXV_MINLEN and UXV_MAXLEN differ only in type. A rule table read from a file needs only the type, two integers and a string.

u8* message

The rule knows what to say when it fails, so the error label and the enabled state come from one place. See the validator.

The string is kept, not copied, so it must outlive the rule. A literal is the usual case; a string built at run time needs UXStr.dup.

message is read only when the rule fails. A rule with no message validates correctly but reports nothing useful.

UXRegex* rx

requireMatch compiles the pattern when the rule is added, so validating on every keystroke costs a match and not a compile.

i32 type

One of the five constants.

UXRegex* rx // UXV_REGEX only; null otherwise
i32 a; i32 b

Operands, per the table above.

u8* message