first commit
This commit is contained in:
commit
efa5080897
127 changed files with 18610 additions and 0 deletions
30
backend/app/phone_number_validators.py
Normal file
30
backend/app/phone_number_validators.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import re
|
||||
|
||||
INDIAN_MOBILE_RE = re.compile(r"^[6-9]\d{9}$")
|
||||
|
||||
|
||||
def normalize_phone_number(value: str) -> str:
|
||||
cleaned = re.sub(r"\D", "", value.strip())
|
||||
if cleaned.startswith("91") and len(cleaned) == 12:
|
||||
cleaned = cleaned[2:]
|
||||
if cleaned.startswith("0") and len(cleaned) == 11:
|
||||
cleaned = cleaned[1:]
|
||||
if not INDIAN_MOBILE_RE.fullmatch(cleaned):
|
||||
raise ValueError("Enter a 10-digit mobile number without +91, e.g. 9876543210")
|
||||
return cleaned
|
||||
|
||||
|
||||
def validate_price(value: float, label: str) -> float:
|
||||
if value < 0:
|
||||
raise ValueError(f"{label} must be zero or greater")
|
||||
if value > 999999:
|
||||
raise ValueError(f"{label} is too large")
|
||||
return round(float(value), 2)
|
||||
|
||||
|
||||
def validate_per_min_price(value: float, label: str) -> float:
|
||||
if value < 0:
|
||||
raise ValueError(f"{label} must be zero or greater")
|
||||
if value > 9999:
|
||||
raise ValueError(f"{label} is too large")
|
||||
return round(float(value), 4)
|
||||
Loading…
Add table
Add a link
Reference in a new issue