Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnifegwu/78aeda9bb3c58e4feae1a688ac38b7db to your computer and use it in GitHub Desktop.
Save johnifegwu/78aeda9bb3c58e4feae1a688ac38b7db to your computer and use it in GitHub Desktop.
Passport Number Extraction and Validation
import re
#Character Classess
#Passport number
pattern = r"[A-Za-z][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"
while True:
num = "Last Name: Doe \n"
num += "Other names: John \n"
num += "DOB:22-Jan-1990 \n"
num += "Passport number: " + input("Enter your 9 digit passport number (eg. A01234567): ") + "\n"
num += "Place of Issue: Lagos, Nigeria. \n"
num += "Date Issued: 31-Oct-2017 \n"
num += "Expires: 30-Oct-2022 \n"
print("Your passport details are: \n")
print(num + "\n Searching.....\n")
match = re.search(pattern, num)
if match:
pNum = match.group()
if (len(pNum) == 9):
print("Marched! \n Your passport number is: {0}".format(pNum))
else:
print("Invalid number!")
else:
print("Invalid number!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment