type 'a t

An 'a t is a validator that parses a form and, on success, returns an 'a.

type 'a reader = string -> 'a or_error
val maybe : 'a -> 'a t

maybe x is a validator that successfully returns x if there were no other validation errors.

val fail : string -> msg:string -> 'a t

fail field ~msg is a validation that fails, reporting msg against field.

val get : string -> (string -> ('a, string) Pervasives.result) -> 'a t

get field conv gets the uploaded field named field and processes it with conv. If conv fails, an error is reported against field.

val string : string reader

string s always accepts s.

val uri : Uri.t reader

uri s tries to parse s as a Uri.

val non_empty : string reader

non_empty s accepts s if it is not the empty string.

val confirm : string -> unit reader

confirm x y accepts y if it is the same as x (useful for enter-this-twice confirmation fields).

val optional : 'a reader -> 'a option reader

optional x is a reader that returns None for the empty string, while using x to read non-empty strings.

val (>>!=) : 'a t -> ('a -> 'b t) -> 'b t

x >>!= f is f y if the validator x successfully produces y.

val (<*>) : 'a t -> 'b t -> ('a * 'b) t

x <*> y validates x and y and, if both are successful, returns the pair of values. If either fails, all errors are reported.

val run : 'a t -> [ `String of string | `File of Multipart.file ] Multipart.StringMap.t -> ('a, State.t) Pervasives.result

run v form_data runs validator v on form data uploaded by the user. It returns 'a on success, or a State.t if there were any validation errors.