mayo v0.2.0 Mayo.String

Summary

Functions

Checks if the string only contains a-z, A-Z, and 0-9

Checks if the string is a valid Luhn number. (Use luhn_ex library)

Checks if the string only contains hex

Checks if the string is a valid IPv4 or IPv6 address

Checks the length of a string

Checks if the string matches the pattern

Checks the maximum length of a string

Checks the minimum length of a string

Checks if the string only contains a-z, A-Z, 0-9 and underscore _

Checks if the string is a valid UUID

Functions

alphanum(value)

Checks if the string only contains a-z, A-Z, and 0-9.

iex> Mayo.String.alphanum("Aa0")
"Aa0"

iex> Mayo.String.alphanum("!$!")
{:error, %Mayo.Error{type: "string.alphanum"}}
credit_card(value)

Checks if the string is a valid Luhn number. (Use luhn_ex library)

iex> Mayo.String.credit_card("378282246310005")
"378282246310005"

iex> Mayo.String.credit_card("123456789123456")
{:error, %Mayo.Error{type: "string.credit_card"}}
hex(value)

Checks if the string only contains hex.

iex> Mayo.String.hex("a1b2")
"a1b2"

iex> Mayo.String.hex("lol")
{:error, %Mayo.Error{type: "string.hex"}}
ip(value)

Checks if the string is a valid IPv4 or IPv6 address.

iex> Mayo.String.ip("210.59.230.150")
"210.59.230.150"

iex> Mayo.String.ip("2001:0DB8:02de:0000:0000:0000:0000:0e13")
"2001:0DB8:02de:0000:0000:0000:0000:0e13"

iex> Mayo.String.ip("test")
{:error, %Mayo.Error{type: "string.ip"}}
length(value, len)

Checks the length of a string.

iex> Mayo.String.length("test", 4)
"test"

iex> Mayo.String.length("test", 5)
{:error, %Mayo.Error{type: "string.length"}}
match(value, pattern)

Checks if the string matches the pattern.

iex> Mayo.String.match("abbbbbc", ~r/^ab+c$/)
"abbbbbc"

iex> Mayo.String.match("ac", ~r/^ab+c$/)
{:error, %Mayo.Error{type: "string.match"}}
max(value, len)

Checks the maximum length of a string.

iex> Mayo.String.max("test", 5)
"test"

iex> Mayo.String.max("bucket", 5)
{:error, %Mayo.Error{type: "string.max"}}
min(value, len)

Checks the minimum length of a string.

iex> Mayo.String.min("test", 3)
"test"

iex> Mayo.String.min("t", 3)
{:error, %Mayo.Error{type: "string.min"}}
token(value)

Checks if the string only contains a-z, A-Z, 0-9 and underscore _.

iex> Mayo.String.token("t_z")
"t_z"

iex> Mayo.String.token("t!z")
{:error, %Mayo.Error{type: "string.token"}}
uuid(value)

Checks if the string is a valid UUID.

iex> Mayo.String.uuid("127862fc-3f59-47c4-9ccf-5d3bfbbe1271")
"127862fc-3f59-47c4-9ccf-5d3bfbbe1271"

iex> Mayo.String.uuid("test")
{:error, %Mayo.Error{type: "string.uuid"}}