17 lines
566 B
Python
17 lines
566 B
Python
import re
|
|
from pydantic import BaseModel, field_validator
|
|
from src.application.domain.exceptions import ApplicationException
|
|
|
|
|
|
class SetPhoneRequest(BaseModel):
|
|
phone: str
|
|
|
|
@field_validator('phone')
|
|
@classmethod
|
|
def validate_russian_phone(cls, v: str) -> str:
|
|
cleaned = re.sub(r'[\s\-\(\)]', '', v)
|
|
pattern = r'^(\+7|8)\d{10}$'
|
|
if not re.match(pattern, cleaned):
|
|
raise ApplicationException(message='Invalid Russian phone number', status_code=429)
|
|
normalized = '+7' + cleaned[-10:]
|
|
return normalized |