FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-validators/src/validators/iban.py at master · sysfce2/python-validators · GitHub
sysfce2
python-validators
Repository navigation
Code
Pull requests
1
(1)
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
python-validators
/
src
/
validators
/
iban.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
44 lines (33 loc) · 1.05 KB
Breadcrumbs
python-validators
/
src
/
validators
/
iban.py
Copy path
File metadata and controls
44 lines (33 loc) · 1.05 KB
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
38
39
40
41
42
43
44
"""IBAN."""
# standard
import
re
# local
from
.
utils
import
validator
def
_char_value
(
char
:
str
):
"""A=10, B=11, ..., Z=35."""
return
char
if
char
.
isdigit
()
else
str
(
10
+
ord
(
char
)
-
ord
(
"A"
))
def
_mod_check
(
value
:
str
):
"""Check if the value string passes the mod97-test."""
# move country code and check numbers to end
rearranged
=
value
[
4
:]
+
value
[:
4
]
return
int
(
""
.
join
(
_char_value
(
char
)
for
char
in
rearranged
))
%
97
==
1
@
validator
def
iban
(
value
:
str
,
/
):
"""Return whether or not given value is a valid IBAN code.
Examples:
>>> iban('DE29100500001061045672')
# Output: True
>>> iban('123456')
# Output: ValidationError(func=iban, ...)
Args:
value:
IBAN string to validate.
Returns:
(Literal[True]): If `value` is a valid IBAN code.
(ValidationError): If `value` is an invalid IBAN code.
"""
return
(
(
re
.
match
(
r"^[a-z]{2}[0-9]{2}[a-z0-9]{11,30}$"
,
value
,
re
.
IGNORECASE
)
and
_mod_check
(
value
))
if
value
else
False
)
Back
|
FazBrowse Home
|
New Git URL