30 lines
939 B
Python
30 lines
939 B
Python
from django.core.validators import RegexValidator, ValidationError
|
|
from django.utils.deconstruct import deconstructible
|
|
|
|
|
|
@deconstructible
|
|
class PhoneNumberValidator(RegexValidator):
|
|
regex = r"^\+?1?\d{9,15}$"
|
|
message = "Telefonnummer muss in diesem Format +999999999999 eingegeben werden. Bis zu 15 Zahlen sind erlaubt."
|
|
|
|
|
|
def validate_domainonly_email(value):
|
|
if not "fet.at" in value:
|
|
raise ValidationError("In der Mailadresse fehlt die richtige Domäne.")
|
|
|
|
|
|
def validate_file_size(value):
|
|
if value.size > 10 * 1024 * 1024:
|
|
raise ValidationError("Die maximale Dateigröße ist 10MB.")
|
|
|
|
|
|
def validate_image_dimension(value):
|
|
if value.height < 150 or value.width < 150:
|
|
raise ValidationError(
|
|
"Das Bild ist zu klein. (Höhe: %(height)s, Breite: %(width)s)",
|
|
params={
|
|
"height": value.height,
|
|
"width": value.width,
|
|
},
|
|
)
|