-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpost_codes.py
33 lines (29 loc) · 1.06 KB
/
post_codes.py
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
#post code validtor
import re
pattern = """
[A-Z] #a single letter
#followed by either:
(
[A-Z] #an another letter
#and either:
(
\d{1,2} #one or two numbers
| #or
\d[A-Z] #a single number followed by a single letter
)
| #or
\d{1,2} #one or two numbers
)
\s\d #space followed by a single number
[A-Z]{2} #two letters
"""
finished = False
while not finished:
post_code = input("Please enter your post code: ")
if len(post_code) == 0:
finished = True
else:
if re.match(pattern,post_code,re.VERBOSE):
print("Valid post code")
else:
print("Invalid post code")