View Source Shapex.Types.String (shapex v0.3.1)

This module provides a type for validating strings.

It's better to use the Shapex.Types.string/1 function to create a schema, since it covers implementation details and provides a more user-friendly API.

Existing validations:

  • :min_length - minimum length
  • :max_length - maximum length
  • :length - exact length
  • :eq - equal
  • :neq - not equal
  • :regex - regex match

Summary

Types

@type t() :: %Shapex.Types.String{validations: term()}
@type type_or_tuple(t) :: t | {t, error_message :: String.t()}
@type validation_rule() ::
  {:min_length, type_or_tuple(integer())}
  | {:max_length, type_or_tuple(integer())}
  | {:length, type_or_tuple(integer())}
  | {:eq, type_or_tuple(String.t())}
  | {:neq, type_or_tuple(String.t())}
  | {:regex, type_or_tuple(String.t())}

Functions

@spec validate(t(), String.t()) :: :ok | {:error, term()}

Callback implementation for Shapex.Type.validate/2.