UXValidationRule
UXValidationRule is one entry in a
UXValidator’s list.
#use <UXKit> // or #import "UXValidator.xc"Overview
Section titled “Overview”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.
One shape for five rules
Section titled “One shape for five rules”a and b mean different things per type. This avoids five separate classes:
| type | a | b | rx |
|---|---|---|---|
UXV_REQUIRED | — | — | — |
UXV_REGEX | — | — | the compiled pattern |
UXV_MINLEN | minimum length | — | — |
UXV_MAXLEN | maximum length | — | — |
UXV_INTRANGE | low | high | — |
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.
The message travels with the rule
Section titled “The message travels with the rule”u8* messageThe 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.
The regex is pre-compiled
Section titled “The regex is pre-compiled”UXRegex* rxrequireMatch compiles the
pattern when the rule is added, so validating on every keystroke costs a match
and not a compile.
Fields
Section titled “Fields”i32 typeOne of the five constants.
UXRegex* rx // UXV_REGEX only; null otherwisei32 a; i32 bOperands, per the table above.
message
Section titled “message”u8* messageConforms to
Section titled “Conforms to”- Inherits
Object
See also
Section titled “See also”UXValidator: the list these live inUXRegex: what aUXV_REGEXrule holds