Spaces:
Build error
Build error
| from pydantic import BaseModel, EmailStr, Field, validator | |
| import phonenumbers | |
| from pydantic import BaseModel, EmailStr, Field, validator | |
| class RegisterUser(BaseModel): | |
| email: EmailStr = Field(..., description="User's email address") | |
| mobile: str = Field(..., description="User's mobile number in international format (e.g., +14155552671)") | |
| name: str = Field(..., min_length=1, description="User's full name") | |
| def validate_mobile(cls, value): | |
| """ | |
| Validate the mobile number format using the phonenumbers library. | |
| """ | |
| try: | |
| parsed_number = phonenumbers.parse(value) | |
| if not phonenumbers.is_valid_number(parsed_number): | |
| raise ValueError("The mobile number is not valid. Please use international format (e.g., +14155552671).") | |
| except Exception: | |
| raise ValueError("The mobile number is not valid. Please use international format (e.g., +14155552671).") | |
| return value | |
| def normalize_email(cls, value): | |
| """ | |
| Normalize email to lowercase. | |
| """ | |
| return value.strip().lower() | |
| def normalize_name(cls, value): | |
| """ | |
| Normalize name by trimming whitespace and capitalizing each word. | |
| """ | |
| return " ".join(word.capitalize() for word in value.strip().split()) |