Skip to content

Instantly share code, notes, and snippets.

@NurElHuda
Created March 13, 2022 06:44
Show Gist options
  • Save NurElHuda/bf28cbc9fe5283ad620bf50ac30317fc to your computer and use it in GitHub Desktop.
Save NurElHuda/bf28cbc9fe5283ad620bf50ac30317fc to your computer and use it in GitHub Desktop.
Validators.py
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