View Source Dsv.Format (Dsv v0.1.1)

Check if the given String matches the regular expression. Dsv.Format module provides a functions to determine if a string matches a regular expression.

Summary

Functions

The valid?/2 function evaluates whether a given string matches a specified regular expression.

The validate/2 function evaluates whether a given string matches a specified regular expression.

The validate/2 function evaluates whether a given string matches a specified regular expression.

Functions

The valid?/2 function evaluates whether a given string matches a specified regular expression.

Parameters

  • data - The string to be checked against the regular expression.
  • format - The regular expression pattern to be used for matching.

Returns

A boolean value:

  • true if the string matches the regex.
  • false if the string does not match the regex.

Examples

iex> Dsv.Format.valid?("string to match", ~r/.* .* .*/)
:true

iex> Dsv.Format.valid?("stringtomatch", ~r/.* .* .*/)
:false
Link to this function

validate(data, options \\ [])

View Source

The validate/2 function evaluates whether a given string matches a specified regular expression.

Parameters

  • data - The string to be checked against the regular expression.
  • format - The regular expression pattern to be used for matching.

Returns

  • :ok if the string matches the regex.
  • {:error, message} if the string does not match the regex.

Examples

iex> Dsv.Format.validate("string to match", ~r/.* .* .*/)
:ok

iex> Dsv.Format.validate("stringtomatch", ~r/.* .* .*/)
{:error, "Value stringtomatch does not match pattern .* .* .*"}
Link to this function

validate(data, format, message)

View Source

The validate/2 function evaluates whether a given string matches a specified regular expression.

Parameters

  • data - The string to be checked against the regular expression.
  • format - The regular expression pattern to be used for matching.
  • message - An custom error message to be returned in case of failure.

Returns

  • :ok if the string matches the regex.
  • {:error, message} if the string does not match the regex.

Examples

iex> Dsv.Format.validate("string to match", ~r/.* .* .*/, "This is wrong.")
:ok

iex> Dsv.Format.validate("stringtomatch", ~r/.* .* .*/, "This is wrong.")
{:error, "This is wrong."}

iex> Dsv.Format.validate("stringtomatch", ~r/.* .* .*/, message: "This is wrong.")
{:error, "This is wrong."}