dominikmifkovic/detoxss/1.0.0

Unavailable. Nobody can download this version any more, with elm or with the Lamdera compiler: github.com/dominikmifkovic/detoxss is gone (deleted or private); Software Heritage has not archived the repo; no fork with the same repo name found; no cached copy. Use another version.

Details

DetoXSS.Validate

General validation helpers for form input.

This module validates whether a value follows application-level rules such as being non-empty, having a specific length, matching a regular expression, or looking like an email address.

Validation is not the same as XSS protection. A valid value may still need sanitization or AST analysis before it is used in an output context.

= Empty
| TooShort Int
| TooLong Int
| InvalidEmail
| InvalidPhone
| InvalidChars String
| WeakPassword String
| Custom String

Possible validation errors returned by the validation helpers.

These errors describe why a value did not pass a validation rule.

type alias Rule =
String -> List ValidationError

Validation rule.

A rule receives a string and returns a list of validation errors. An empty list means that the value passed that rule.

validate : List Rule -> String -> Result (List ValidationError) ValidatedInput

Run a list of validation rules against a string.

The input is trimmed before validation. If all rules pass, the cleaned value is returned as ValidatedInput.

validateEmail : String -> Result (List ValidationError) ValidatedInput

Validate a simple email address.

This checks the general shape of an email address. It does not verify whether the address actually exists.

validatePhone : String -> Result (List ValidationError) ValidatedInput

Validate a phone-like value.

The value may contain digits, spaces, plus signs, dashes, and parentheses.

validateUsername : String -> Result (List ValidationError) ValidatedInput

Validate a username.

The username must be non-empty, have an allowed length, and contain only letters, digits, underscores, dots, or dashes.

validatePassword : String -> Result (List ValidationError) ValidatedInput

Validate a password.

The password must be non-empty, have a minimum length, and contain a mixture of character classes.

nonEmpty : String -> List ValidationError

Require a non-empty value.

minLength : Int -> String -> List ValidationError

Require a minimum string length.

maxLength : Int -> String -> List ValidationError

Require a maximum string length.

allowedChars : Regex -> String -> Rule

Require the value to match a regular expression.

The description is used in the InvalidChars error when the value does not match.

matchesRegex : Regex -> ValidationError -> Rule

Create a validation rule from a regular expression and custom error.