Module Bogue.Ti_validate

module Ti_validate: sig .. end

Add a validator to a Text_input

A validator is a small icon, located next to a Text entry, indicating whether the text typed by the user is "valid" under certain rules (for instance, a valid email address). In strict mode, the validator can also completely prevent the user from typing any invalid string.

Dependency graph

type t 
type status = bool option 

String status:

  1. Some true = good text
  2. Some false = bad text
  3. None = undecided yet
type validator = string -> status * string option 

A validator function takes a string that the user has typed in the Text_input widget, and returns:

  1. the status: "is this string valid?"
  2. optionally, the string that should be entered instead. None means: keep the user entry.
val get_status : t -> status
val get_layout : t -> Layout.t
val get_text_input : t -> Widget.t
val get_text : t -> string
val regexp_validator : ?strict:bool -> string -> validator

Construct a validator function from a regular expression. If strîct is true, the complete string must match the complete regular expression to validate. Only valid text is allowed (so make sure that the default string does validate!)

If strict=false, the status stays "undecided" as long as the whole string is a prefix of a potential string that would strictly match. Thus, the user is allowed to type strings that are "not complete yet".

val make : validator ->
?bg:Draw.rgb ->
?prompt:string -> ?size:int -> string -> t

Return a layout containing a Text Entry and a Validity indicator; also return a function to examine the validity of the last user entry.

val of_regexp : ?strict:bool ->
string ->
?bg:Draw.rgb ->
?prompt:string -> ?size:int -> string -> t

Same as Ti_validate.make, with a validator obtained from a regular expression via Ti_validate.regexp_validator.

module Email: sig .. end

Implement email validation following HTML specs.