FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
validators/validators/length.py at master · pythonthings/validators · GitHub
pythonthings
validators
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
validators
/
validators
/
length.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (29 loc) · 970 Bytes
Breadcrumbs
validators
/
validators
/
length.py
Copy path
File metadata and controls
37 lines (29 loc) · 970 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from
.
between
import
between
from
.
utils
import
validator
@
validator
def
length
(
value
,
min
=
None
,
max
=
None
):
"""
Return whether or not the length of given string is within a specified
range.
Examples::
>>> length('something', min=2)
True
>>> length('something', min=9, max=9)
True
>>> length('something', max=5)
ValidationFailure(func=length, ...)
:param value:
The string to validate.
:param min:
The minimum required length of the string. If not provided, minimum
length will not be checked.
:param max:
The maximum length of the string. If not provided, maximum length
will not be checked.
.. versionadded:: 0.2
"""
if
(
min
is
not
None
and
min
<
0
)
or
(
max
is
not
None
and
max
<
0
):
raise
AssertionError
(
'`min` and `max` need to be greater than zero.'
)
return
between
(
len
(
value
),
min
=
min
,
max
=
max
)
Back
|
FazBrowse Home
|
New Git URL