간단한 정규식을 이용하여 날짜형태의 포맷을 확인하였다.
digit type 및 자리수를 명시하여 boolean값으로 return하는 함수를 만들어 보았다.
import re
def check_date_format(input_date):
regex = r'\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}'
return bool(re.match(regex, input_date))
print(check_date_format("2022-05-30 18:30:25"))
print(check_date_format("2022-5-3 18:30:25"))
print(check_date_format("2022-5월-3일 18:30:25"))
결과
True
False
False
추가로, 입력받은 Text가 숫자형태인지 확인하는 함수
input_value = input("입력값 : ")
print(input_value.isdigit())
결과
입력값 : a
False
입력값 : 12
True
'Code Story' 카테고리의 다른 글
[꿀팁] 쉘스크립트 만들기 (0) | 2023.07.21 |
---|---|
미디어 컨트롤을 위한 이벤트 발생. (0) | 2022.04.18 |
클래스 속성과 인스턴스 속성 (0) | 2022.01.26 |
Class of Python - 클래스 기본적인 사용 (0) | 2022.01.26 |
OOP(Object-Oriented Programming) of Python (1) | 2022.01.25 |