~linuxgoose/bocpress

ref: 5204e11e63274f2b2f18a72cc43925cfc58d32ed bocpress/main/validators.py -rw-r--r-- 585 bytes
5204e11eJordan Robinson fix user update form to account for allow_docs_user env variable 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from django.core import validators as dj_validators
from django.core.exceptions import ValidationError


class AlphanumericHyphenValidator(dj_validators.RegexValidator):
    regex = r"^[a-z\d-]+\Z"
    message = "Invalid value. Should include only lowercase letters, numbers, and -"
    flags = 0


class HyphenOnlyValidator(dj_validators.RegexValidator):
    regex = r"^[-]*$"
    message = "Invalid value. Cannot be just hyphens."
    inverse_match = True
    flags = 0


def validate_domain_name(value):
    if "." not in value:
        raise ValidationError("Invalid domain name")