Validators
Built-in field validators, attached to any field through BaseField(validators=[...])
and run by BaseField.validate. For an overview of the validation flow, see
Fields.
starlette_admin.validators.length(min=-1, max=-1, message=None)
Requires min <= len(value) <= max. Unset bounds are not checked.
Source code in starlette_admin/validators.py
starlette_admin.validators.number_range(min=None, max=None, message=None)
Requires min <= value <= max. Unset bounds are not checked.
Source code in starlette_admin/validators.py
starlette_admin.validators.number_gt(min, message=None)
Requires value > min (strict). For an inclusive bound, use
number_range.
Source code in starlette_admin/validators.py
starlette_admin.validators.number_lt(max, message=None)
Requires value < max (strict). For an inclusive bound, use
number_range.
Source code in starlette_admin/validators.py
starlette_admin.validators.date_range(min=None, max=None, message=None)
Requires min <= value <= max. Unset bounds are not checked.
Bounds must be comparable with the field's parsed value (date, datetime,
time, or Arrow, matching the field type). A bound may also be a zero-argument
callable returning the bound, evaluated on each validation, e.g.
date_range(min=datetime.date.today) to reject past dates.
Source code in starlette_admin/validators.py
starlette_admin.validators.regexp(pattern, flags=0, message=None)
Requires the value to match pattern (via re.match).
Source code in starlette_admin/validators.py
starlette_admin.validators.disallow(pattern, flags=0, message=None)
Rejects values containing a match for pattern (via re.search), the
inverse of regexp. Useful to block
unwanted content, e.g. disallow(r"<[^>]+>") to reject HTML tags.
Source code in starlette_admin/validators.py
starlette_admin.validators.mac_address(message=None)
Requires the value to be a valid MAC address, six pairs of hex digits
separated consistently by : or -.
Source code in starlette_admin/validators.py
starlette_admin.validators.slug(allow_underscores=False, message=None)
Requires the value to be a URL-safe slug: lowercase letters, digits, and
single hyphens between segments. allow_underscores also permits _.
Source code in starlette_admin/validators.py
starlette_admin.validators.color(formats=('hex',), message=None)
Requires the value to be a CSS color in one of formats: "hex"
(#rgb, #rgba, #rrggbb, or #rrggbbaa), "rgb" (rgb()
or rgba()), and "hsl" (hsl() or hsla()).
Source code in starlette_admin/validators.py
starlette_admin.validators.email(message=None, **options)
Requires the value to be a valid email address, checked with the
email-validator package (pip install starlette-admin[email]).
options are forwarded to email_validator.validate_email. Deliverability
(DNS/MX) checks are disabled by default; pass check_deliverability=True
to enable them.
Source code in starlette_admin/validators.py
starlette_admin.validators.url(schemes=('http', 'https', 'ftp', 'ftps'), max_length=2048, message=None)
Requires the value to be an absolute URL with a valid scheme and host.
schemes restricts the accepted schemes (default http/https/ftp/
ftps); pass None to accept any scheme. The host must be localhost, a
valid IPv4/IPv6 address, or a domain name with a valid TLD (internationalized
domains are accepted via IDNA encoding). max_length rejects overly long
values before parsing, to avoid pathological input.
Source code in starlette_admin/validators.py
starlette_admin.validators.uuid(version=None, message=None)
Requires the value to be a valid UUID. If version is set (1, 3, 4, or 5),
also requires the UUID to be of that version.
Source code in starlette_admin/validators.py
starlette_admin.validators.ip_address(ipv4=True, ipv6=False, message=None)
Requires the value to be a valid IP address. ipv4 and ipv6 control
which address families are accepted; at least one must be True.
Source code in starlette_admin/validators.py
starlette_admin.validators.any_of(values, message=None)
Requires the value to be one of values.
Source code in starlette_admin/validators.py
starlette_admin.validators.none_of(values, message=None)
Requires the value to not be any of values.
Source code in starlette_admin/validators.py
starlette_admin.validators.items(*validators)
Applies validators to each element of a multi-value field's list
(e.g. TagsField), stopping at the first
error. Example: TagsField("tags", validators=[items(length(min=3))]).
Source code in starlette_admin/validators.py
File validators
starlette_admin.validators.file_size(max_size, message=None)
Rejects uploads larger than max_size bytes.
Source code in starlette_admin/validators.py
starlette_admin.validators.file_type(accept, message=None)
Rejects uploads not matching accept, a comma-separated list of file
specifiers as understood by the HTML file input (e.g., ".pdf",
"image/*", "image/png,.svg").
Source code in starlette_admin/validators.py
starlette_admin.validators.valid_image(message=None)
Rejects uploads that Pillow cannot verify as images.
Source code in starlette_admin/validators.py
starlette_admin.validators.image_size(min_width=None, min_height=None, max_width=None, max_height=None, message=None)
Rejects image uploads whose pixel dimensions fall outside the given bounds. Unset bounds are not checked. Requires Pillow; uploads Pillow cannot open are rejected.