View Source Dsv.Format (Dsv v0.2.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 thestring
matches theregex
.false
if thestring
does not match theregex
.
Examples
iex> Dsv.Format.valid?("string to match", ~r/.* .* .*/)
:true
iex> Dsv.Format.valid?("stringtomatch", ~r/.* .* .*/)
:false
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 thestring
matches theregex
.{:error, message}
if thestring
does not match theregex
.
Examples
iex> Dsv.Format.validate("string to match", ~r/.* .* .*/)
:ok
iex> Dsv.Format.validate("stringtomatch", ~r/.* .* .*/)
{:error, "Value stringtomatch does not match pattern .* .* .*"}
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 thestring
matches theregex
.{:error, message}
if thestring
does not match theregex
.
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."}