Library
Module
Module type
Parameter
Class
Class type
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 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).
optional x
is a reader that returns None
for the empty string, while using x
to read non-empty strings.
x >>!= f
is f y
if the validator x
successfully produces y
.
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.