Created
March 13, 2022 06:44
-
-
Save NurElHuda/bf28cbc9fe5283ad620bf50ac30317fc to your computer and use it in GitHub Desktop.
Validators.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from rest_framework import serializers | |
class DzPhoneFormatValidator(object): | |
def __call__(self, phone): | |
PHONE_REGEXP = re.compile("(0|\+213|00213){1}([1-9]){1}([0-9]{8})") | |
if not PHONE_REGEXP.match(phone): | |
message = "Invalid phone format" | |
raise serializers.ValidationError(message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment