Type Methods
Zangar provides convenient validation methods for some types.
For example:
>>> z.str().strip().min(1).max(20).parse(' hello ')
'hello'
# equivalent to:
>>> z.str().transform(str.strip).ensure(lambda x: len(x) >= 1).ensure(lambda x: len(x) <= 20).parse(' hello ')
'hello'
String
.max
Validate the maximum length of a string.
.min
Validate the minimum length of a string.
.strip
Trim whitespace from both ends.
>>> z.str().strip().parse(' string ')
'string'
# equivalent to:
>>> z.str().transform(str.strip).parse(' string ')
'string'
Number
.gt
Validate the number is greater than a given value.
.gte
Validate the number is greater than or equal to a given value.
.lt
Validate the number is less than a given value.
.lte
Validate the number is less than or equal to a given value.
Datetime
is_aware
Validate the datetime is aware.
is_naive
Validate the datetime is naive.