core.validation¶
src.core.validation
¶
Validation framework for input validation.
This module provides utility functions for common validation patterns. All validation functions return Result types for consistent error handling.
Usage
from src.core.validation import validate_email, validate_not_empty from src.core.result import Success, Failure
result = validate_email("user@example.com") match result: case Success(email): # Email is valid pass case Failure(error): # Handle validation error print(error.message)
Classes¶
Functions¶
validate_not_empty
¶
Validate that a value is not empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Value to validate. |
required |
field_name
|
str
|
Name of the field being validated. |
required |
Returns:
| Type | Description |
|---|---|
Result[Any, ValidationError]
|
Success with value if not empty, Failure with ValidationError otherwise. |
Source code in src/core/validation.py
validate_email
¶
Validate email format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
Email address to validate. |
required |
Returns:
| Type | Description |
|---|---|
Result[str, ValidationError]
|
Success with email if valid, Failure with ValidationError otherwise. |
Source code in src/core/validation.py
validate_min_length
¶
Validate minimum string length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
String to validate. |
required |
min_length
|
int
|
Minimum required length. |
required |
field_name
|
str
|
Name of the field being validated. |
required |
Returns:
| Type | Description |
|---|---|
Result[str, ValidationError]
|
Success with value if valid, Failure with ValidationError otherwise. |
Source code in src/core/validation.py
validate_max_length
¶
Validate maximum string length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
String to validate. |
required |
max_length
|
int
|
Maximum allowed length. |
required |
field_name
|
str
|
Name of the field being validated. |
required |
Returns:
| Type | Description |
|---|---|
Result[str, ValidationError]
|
Success with value if valid, Failure with ValidationError otherwise. |