jaredramirez / elm-field / Field.String

A pre-applied String version of the Field type, and validation function to go along with them.

Base


type alias Field =
Field String String

A field to hold a String value, with an error type of String. See Field


type alias ViewConfig msg =
Field.ViewConfig String String msg

A view config object for String fields. See ViewConfig


type alias ValidationFunc =
Field.ValidationFunc String String

A validation function for a String Field

Validation

notEmpty : ValidationFunc

Enforces that a field is not empty

email : ValidationFunc

Enforce that a field is an email.

The format the email just follow is:

[ >1 upper,lower,digit,symbol ]@[ >2 upper,lower,digit,symbol ].[ >2 upper,lower,digit, ]

To validate emails, we don't use regex we use elm-tools/parser to validate. If there's a specific format you need your emails to follow, you can easily implement your own validation function.

numeric : ValidationFunc

Enforce that a field contains only numbers.

nonnumeric : ValidationFunc

Enforce that a field does not contains only numbers.

atLeast : Basics.Int -> ValidationFunc

Enforce that a field is at least x characters long

atMost : Basics.Int -> ValidationFunc

Enforce that a field is at most x characters long

exactly : Basics.Int -> ValidationFunc

Enforce that a field is exactly x characters long

optional : ValidationFunc -> ValidationFunc

A validation function wrapper that will only run the ValidationFunc if the provided if the field's value is not "". If the field's value is "" then this will just return the field