DValidate (d_validate v0.1.0)
A module for validating input fields in Elixir applications.
Summary
Functions
Validates if a value matches the given regex pattern.
Validates if a value is present.
Validates if a value is of the specified type.
Functions
Link to this function
validate_format(value, regex)
Validates if a value matches the given regex pattern.
Examples
iex> DValidate.validate_format("abc 123", ~r/^w+$/)
{:error, :field_name, "has an invalid format"}
Link to this function
validate_presence(value, field_name)
Validates if a value is present.
Examples
iex> DValidate.validate_presence("value", :field_name)
:ok
iex> DValidate.validate_presence(nil, :field_name)
{:error, :field_name, "is required"}
Link to this function
validate_type(value, type)
Validates if a value is of the specified type.
Examples
iex> DValidate.validate_type(1, :integer)
:ok
iex> DValidate.validate_type("value", :string)
:ok
iex> DValidate.validate_type(1.0, :float)
:ok
iex> DValidate.validate_type("value", :integer)
{:error, :integer, "is invalid"}