validation.py 599 B

12345678910111213141516171819202122
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django.core.exceptions import ValidationError
  4. from django.core.validators import RegexValidator
  5. from .utils import re_chat_url
  6. def validate_v4(address):
  7. if address.version != 4:
  8. raise ValidationError('{} is not an IPv4 address'.format(address))
  9. def validate_v6(address):
  10. if address.version != 6:
  11. raise ValidationError('{} is not an IPv6 address'.format(address))
  12. chatroom_url_validator = RegexValidator(
  13. regex=re_chat_url,
  14. message="Enter a value of the form <proto>://<server>/<channel>")