{% extends "admin/change_form.html" %} {% load static %} {% block after_field_sets %} {{ block.super }} {% if original %}

Validator Help

How to configure validators:

Enter the validator parameters in JSON format in the "Validator params" field. Here are examples for each validator type:

Validator Type Description JSON Parameters Example
MinValueValidator Validates that the value is greater than or equal to a minimum {"limit_value": 10}
MaxValueValidator Validates that the value is less than or equal to a maximum {"limit_value": 100}
MinLengthValidator Validates that the string length is at least a minimum {"limit_value": 5}
MaxLengthValidator Validates that the string length does not exceed a maximum {"limit_value": 255}
RegexValidator Validates that the value matches a regular expression pattern {"regex": "^[A-Z][0-9]{3}$", "message": "..."}
EmailValidator Validates email address format {} (no parameters needed)
URLValidator Validates URL format {} or {"schemes": ["http", "https"]}
validate_slug Validates slug format (letters, numbers, hyphens, underscores) {} (no parameters needed)
validate_ipv4_address Validates IPv4 address format {} (no parameters needed)
validate_ipv6_address Validates IPv6 address format {} (no parameters needed)
FileExtensionValidator Validates file extensions in file paths {"allowed_extensions": ["jpg", "png", "pdf"]}

💡 Tips

  • The "Order" field determines the execution sequence (lowest first)
  • Multiple validators can be applied to the same parameter
  • Validators are executed when saving the parameter value
  • For validators without parameters, use an empty JSON object: {}
  • All JSON parameters must use double quotes, not single quotes

📖 Common Use Cases

  • Age restriction: MinValueValidator with {"limit_value": 18} and MaxValueValidator with {"limit_value": 120}
  • Percentage validation: MinValueValidator {"limit_value": 0} + MaxValueValidator {"limit_value": 100}
  • Username format: RegexValidator with {"regex": "^[a-z0-9_]{3,20}$"}
  • Password strength: MinLengthValidator {"limit_value": 8} + RegexValidator for complexity
{% endif %} {% endblock %}