argclz.validator.StrValidatorBuilder#

class argclz.validator.StrValidatorBuilder[source]#

Bases: AbstractTypeValidatorBuilder[str]

a str validator

__init__()[source]#

Methods Summary

__init__()

contains(*texts)

Check if string values contain a substring

ends_with(suffix)

Check if string values end with a substring

freeze(*args, **kwargs)

(internal use) return a copy of itself.

length_in_range(a, b, /)

Enforce a string length range

match(r)

Check if string matches a regular expression

one_of(options)

Check if string is one of the allow options

optional()

starts_with(prefix)

Check if string values start with a substring

__call__(value)

Details

length_in_range(a, b, /)[source]#

Enforce a string length range

Parameters:
  • a (int | None)

  • b (int | None)

Return type:

StrValidatorBuilder

match(r)[source]#

Check if string matches a regular expression

Parameters:

r (str | Pattern)

Return type:

StrValidatorBuilder

starts_with(prefix)[source]#

Check if string values start with a substring

Parameters:

prefix (str)

Return type:

StrValidatorBuilder

ends_with(suffix)[source]#

Check if string values end with a substring

Parameters:

suffix (str)

Return type:

StrValidatorBuilder

contains(*texts)[source]#

Check if string values contain a substring

Parameters:

texts (str)

Return type:

StrValidatorBuilder

one_of(options)[source]#

Check if string is one of the allow options

Parameters:

options (Collection[str])

Return type:

StrValidatorBuilder

__call__(value)#
Parameters:

value (Any) – type-casted value.

Returns:

True if value pass the validation.

Raises:

ValueError – when value does not pass the validation.

Return type:

bool

freeze(*args, **kwargs)#

(internal use) return a copy of itself.

Return type:

Self

optional()#
Return type:

Self