-
Notifications
You must be signed in to change notification settings - Fork 56
Description
Feature description:
String fields can allow white space, but often leading or trailing whitespace characters are not desired.
It would be nice if there was a validation rule to enforce string values do not start or end with whitespace characters.
Problem it solves or use case:
Validation of string field values to not include unwanted whitespace.
This can currently be worked around by using pattern rules that forbid whitespace, but in my opinion this requires more complicated patterns that are harder to read than an explicit validation rule.
I think the use case might be common enough to warrant a standard rule.
Proposed implementation or solution:
Validation rules like
(buf.validate.field).string.no_leading_whitespace = true,
(buf.validate.field).string.no_trailing_whitespace = true,
(buf.validate.field).string.no_surrounding_whitespace = true
with no_surrounding_whitespace forbidding both leading and trailing whitespace (the most common case I would expect).
Contribution:
Examples or references:
Django's CharField form field has a strip option to avoid leading and trailing whitespace. While not a validation rule as it changes the value, it addresses the same issue.
Additional context: