Open roberthsu2003 opened 4 months ago
import re
phone_num = input('請輸入手機號碼(xxx) xxx-xxxx: ')
phoneNumRegex = re.compile(r'\(\d{3}\) \d{3}-\d{4}')
match1 = phoneNumRegex.match(phone_num)
if match1 is not None:
print(f'{match1.group()}: 格式符合')
else:
print('格式不符')
date = input('請輸入日期yyyy-mm-dd: ')
dateRegex = re.compile(r'\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])')
match2 = dateRegex.match(date)
if match2 is not None:
print(f'{match2.group()}: 格式符合')
else:
print('格式不符')
import re
phone_num =input("請輸入有效日期(xxx) xxx-xxxx:")
phoneNumberRegex:re.Pattern = re.compile(r'\(\d{3}\) \d{3}-\d{4}')
match:re.Match | None = re.match(phoneNumberRegex, phone_num)
if match is not None:
print(f"有效的電話號碼:{match.group()}")
else:
print(f"無效的電話號碼:{phone_num}")
date =input("請輸入有效日期xxxx-xx-xx:")
daterangeRegex:re.Pattern = re.compile(r'\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[0-1])')
match1:re.Match | None = re.match(daterangeRegex, date)
if match1 is not None:
print(f"有效的日期:{match1.group()}")
else:
print(f"無效日期:{date}")
import re
phone_num =input("請輸入電話號碼驗證:(xxx) xxx-xxxx:")
phoneNumberRegex:re.Pattern = re.compile(r'\(\d{3}\) \d{3}-\d{4}')
match:re.Match | None = re.match(phoneNumberRegex, phone_num)
if match is not None:
print(f"有效的電話號碼:{match.group()}")
else:
print(f"無效的電話號碼:{phone_num}")
date =input("請輸入日期驗證:xxxx-xx-xx:")
daterangeRegex:re.Pattern = re.compile(r'\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[0-1])')
match1:re.Match | None = re.match(daterangeRegex, date)
if match1 is not None:
print(f"有效的日期:{match1.group()}")
else:
print(f"無效的日期:{date}")
import re
phone_num = input('請輸入手機號碼(xxx) xxx-xxxx: ')
phoneNumRegex = re.compile(r'\(\d{3}\) \d{3}-\d{4}')
match1 = phoneNumRegex.match(phone_num)
if match1 is not None:
print(f'{match1.group()}: 格式符合')
else:
print('格式不符')
import re
date = input('請輸入日期yyyy-mm-dd: ')
dateRegex = re.compile(r'\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])')
match1 = dateRegex.match(date)
if match1 is not None:
print(f'{match1.group()}: 格式符合')
else:
print('格式不符')
import re
phone_num = input("請輸入手機號碼(xxxx)-xxx-xxx:")
phoneNumRegex:re.Pattern = re.compile(r'(\(\d{4}\))-(\d{3})-(\d{3})')
match1:re.Match | None = re.match(phoneNumRegex,phone_num)
if match1 is not None:
print(f"{match1.group()}有效的電話")
else:
print(f"{phone_num}無效的電話")
date = input("請輸入日期xxxx-xx-xx:")
dateRegex:re.Pattern=re.compile(r'\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])')
match_date:re.match=re.match(dateRegex,date)
if match_date is not None:
print(f'你輸入的日期為{match_date.group()}')
else:
print(f"{date}為無效的日期,請重新輸入")
有效的電話、日期
無效的電話、日期
import re
phone_num = input("請輸入手機號碼:(xxx) xxx-xxxx")
phoneNumRegex:re.Pattern = re.compile(r'(\(\d{3}\)) \d{3}-\d{4}')
match1:re.Match | None = re.match(phoneNumRegex,phone_num)
if match1 is not None:
print(f"有效的電話號碼:{match1.group()}")
else:
print(f"無效的電話號碼:{phone_num}")
date = input("請輸入有效日期:xxxx-xx-xx")
dateRegex:re.Pattern = re.compile(r'\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])')
match2:re.Match | None = re.match(dateRegex,date)
if match2 is not None:
print(f"有效日期:{match2.group()}")
else:
print(f"無效日期:{date}")