-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidators.py
More file actions
30 lines (24 loc) · 923 Bytes
/
Copy pathvalidators.py
File metadata and controls
30 lines (24 loc) · 923 Bytes
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
import re
from datetime import datetime
def validate_required(value, field_name):
"""필수 입력값이 비어있는지 검증한다."""
if not value or not str(value).strip():
return f"{field_name}은(는) 필수 입력값입니다."
return None
def validate_email(email):
"""이메일 형식을 검증한다."""
if not email or not email.strip():
return None
pattern = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
if not re.match(pattern, email.strip()):
return "이메일 형식이 올바르지 않습니다."
return None
def validate_date(date_str):
"""날짜 형식(YYYY-MM-DD)을 검증한다."""
if not date_str or not date_str.strip():
return None
try:
datetime.strptime(date_str.strip(), "%Y-%m-%d")
return None
except ValueError:
return "날짜 형식이 올바르지 않습니다. (YYYY-MM-DD)"