Answer the question
In order to leave comments, you need to log in
Phone number validator with RegexValidator?
I'm trying to validate an input for a phone number using RegexValidator.
I wrote the following in the user model:
phone_regex = RegexValidator(
regex=r'^\+?1?\d{9,15}$',
message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed."
)
phone = models.CharField(validators=[phone_regex], max_length=17, blank=True)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question