add product
This commit is contained in:
1 parent
423d4cf40e
commit
c8d45dd07c
58 files changed
+8309
-674
No files matched your search
@@ -0,0 +1,14 @@
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
|
||||
def normalize_mobile(value):
|
||||
"""Keep the integer storage format while accepting Iranian mobile formats."""
|
||||
mobile = str(value).strip().translate(str.maketrans("۰۱۲۳۴۵۶۷۸۹٠١٢٣٤٥٦٧٨٩", "01234567890123456789"))
|
||||
mobile = mobile.replace(" ", "").replace("-", "")
|
||||
for prefix in ("+98", "0098", "98", "0"):
|
||||
if mobile.startswith(prefix) and len(mobile) == 10 + len(prefix):
|
||||
mobile = mobile[len(prefix):]
|
||||
break
|
||||
if len(mobile) != 10 or not mobile.isascii() or not mobile.isdigit() or not mobile.startswith("9"):
|
||||
raise ValidationError({"mobile": "شماره موبایل معتبر وارد کنید."})
|
||||
return int(mobile)
|
||||
Reference in new issue
Block a user