S
S
Socrates2018-02-02 13:22:56
Django
Socrates, 2018-02-02 13:22:56

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)

when you enter a clumsy number into the input, the data is not saved, excellent, but
I expected that when you enter letters into the input, what was indicated in the message will fly out.
What can be connected with this, maybe this variable should be displayed somewhere?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2018-02-02
@Karmov69

https://docs.djangoproject.com/en/2.0/ref/validato...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question