-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathValidations.py
More file actions
33 lines (27 loc) · 980 Bytes
/
Validations.py
File metadata and controls
33 lines (27 loc) · 980 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
31
32
33
from abc import ABC, abstractmethod
import re
# Strategy interfaces
class EmployeeIDValidationStrategy(ABC):
@abstractmethod
def validate(self, employee_id):
pass
class PasswordValidationStrategy(ABC):
@abstractmethod
def validate(self, password):
pass
# Concrete implementations of strategies
class RegexEmployeeIDValidation(EmployeeIDValidationStrategy):
def validate(self, employee_id):
# Validate employee ID using regex
return bool(re.match(r'^[a-zA-Z0-9_-]+$', employee_id))
class RegexPasswordValidation(PasswordValidationStrategy):
def validate(self, password):
# Validate password using regex
return bool(re.match(r'^[a-zA-Z0-9!@#$%^&*()_-]+$', password))
# Context class that uses the strategies
class ValidationContext:
def __init__(self, strategy, data):
self.strategy = strategy
self.data = data
def validate(self):
return self.strategy.validate(self.data)