Home

Awesome

A simple library to validate strings in the V language

CI

The main purpose of this library is to validate the user input in the web applications. Due to the nature of the input in the web (it's almost always strings), the main focus is on validating strings.

Installation and Usage

<!-- Install the library with `v install endeveit.validate` -->

The library provides a number of validators and sanitizers

Validators

Here's the full list of the currently available validators:

ValidatorDescription
is_boolChecks if the string is a bool
is_eqChecks if the string is equal to another int, float or string value
is_neChecks if the string is not equal to another int, float or string value
is_inChecks if the string is in an array of allowed values
is_gtChecks if the string is greater than another int, float or string value
is_geChecks if the string is greater or equal to another int, float or string value
is_ltChecks if the string is less than another int, float or string value
is_leChecks if the string is less or equal to another int, float or string value
is_emailChecks if the string is a valid email address
is_fqdnChecks if the string is a Fully Qualified Domain Name
is_floatChecks if the string is a float
is_intChecks if the string is an integer
is_ipChecks if the string is an IP address (v4 or v6)
is_ipv4Checks if the string is an IPv4 address
is_ipv6Checks if the string is an IPv6 address
is_regex_matchChecks if the string matches the regular expression
is_regex_validChecks if regular expression syntax is correct
is_uuidChecks if the string is a valid UUID
is_uuid_v3Checks if the string is a valid UUID v3
is_uuid_v4Checks if the string is a valid UUID v4
is_uuid_v5Checks if the string is a valid UUID v5

Validation chain

All validators listed above can be used within a validation chain.

Here's the list of additional functions and methods:

SanitizerDescription
new_chainReturns the new validation chain
.bailStops running validations if any of the previous ones have failed
.validateRuns the validation chain against the provided value
.get_errorsReturns list of the validation errors

Example usage of the chain:

mut ch := new_chain()
ch.is_gt(dst: 'a')
ch.is_le(dst: 'c')
ch.bail()
ch.is_int({}) # this won't be reached ever

assert ch.validate('z') == false

Sanitizers

Here's the full list of the currently available sanitizers:

SanitizerDescription
to_boolConverts the string to a boolean value
to_floatConverts the string to a float value
to_intConverts the string to an integer value