Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

연습문제 26 입력 값 검증 #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions pythontraning/validating_inputs/validating_inputs_rudia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import re


class inputVlaueCheck(object):

def __init__(self):
pass

def check_value_name(self, label, answer):
if answer is '':
print("The "+label+" name must be filled in")
elif len(answer) == 1:
print("\""+answer+"\" is not a valid "+label+ " name. It is too short.")

def enter_name(self, label):
a = input("Enter the "+label+" name:")
self.check_value_name(label, a)

def enter_zip_code(self):
answer = input("Enter the ZIP code:")
p = re.compile('^[0-9]*$')
m = p.match(answer)
if not m:
print('The ZIP code must be numeric:' + answer)

def enter_employee_id(self):
answer = input("Enter the Employee ID:")
p = re.compile('([a-zA-Z]{1,2})\-([0-9]{4})')
m = p.match(answer)
if not m:
print(answer+' is not a valid ID')


class excute_init(object):
if __name__ == "__main__":
inputVal = inputVlaueCheck()
inputVal.enter_name("first")
inputVal.enter_name("last")
inputVal.enter_zip_code()
inputVal.enter_employee_id()