0
class SomeSerializer(serializers.ModelSerializer):
    first_name = serializers.CharField(validators=[RegexValidator(
        regex=(r"^[a-zA-Z_ \- \. \' ]+$"), message="Enter a valid first name")])
    phone = serializers.IntegerField(source="user.phone")

Now, this phone field since called an integer field, is giving a validation error, "Enter valid integer". How can I make that a custom message?

Suryaraj PS
  • 3
  • 1
  • 5
  • 1
    Does this answer your question? [Proper way to declare custom exceptions in modern Python?](https://stackoverflow.com/questions/1319615/proper-way-to-declare-custom-exceptions-in-modern-python) – Cresht Mar 03 '22 at 05:27
  • Does this answer your question? [Django REST Framework custom fields validation](https://stackoverflow.com/questions/31278418/django-rest-framework-custom-fields-validation) – rs_punia Mar 03 '22 at 06:34

0 Answers0