-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRussian_postal_code_checker.py
More file actions
48 lines (41 loc) · 1.18 KB
/
Russian_postal_code_checker.py
File metadata and controls
48 lines (41 loc) · 1.18 KB
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
45
46
47
48
def start_digit_valid(func):
def start_digit_validate(postcode):
'''
valid post code cannot start with digit 0, 5, 7, 8 or 9
'''
if postcode[0] in '05789':
return False
return func(postcode)
return start_digit_validate
def length_valid(func):
def length_validator(postcode):
'''
A valid postcode should be 6 digits
'''
MANDITORY_LENGTH = 6
if len(postcode) != MANDITORY_LENGTH:
return False
return func(postcode)
return length_validator
def only_numbers(func):
def only_numbers(postcode):
'''
A valid postcode should be 6 digits with no white spaces, letters or other symbols.
'''
if any([c not in '0123456789' for c in postcode]):
return False
return func(postcode)
return only_numbers
@only_numbers
@length_valid
@start_digit_valid
def zipvalidate(postcode):
return True
print zipvalidate( '198328' )
print zipvalidate( '310003' )
print zipvalidate( '424000' )
print zipvalidate( '12A483' )
print zipvalidate( '1@63' )
print zipvalidate( '111' )
print zipvalidate( '056879' )
print zipvalidate( '1111111' )