You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
850 B
29 lines
850 B
|
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from phonenumber_field.phonenumber import to_python
|
|
from phonenumbers.phonenumberutil import is_possible_number
|
|
|
|
|
|
|
|
|
|
def validate_possible_number(phone, country=None):
|
|
phone_number = to_python(phone, country)
|
|
if (
|
|
phone_number
|
|
and not is_possible_number(phone_number)
|
|
or not phone_number.is_valid()
|
|
):
|
|
raise ValidationError(
|
|
"The phone number entered is not valid.", code="invalid"
|
|
)
|
|
return phone_number
|
|
|
|
def validate_type_code(value):
|
|
from rest_framework import serializers
|
|
if not value.isdigit():
|
|
raise serializers.ValidationError('کد باید شامل اعداد باشد.')
|
|
if len(value) != 5:
|
|
raise serializers.ValidationError('کد باید ۵ رقمی باشد.')
|
|
return value
|