Feature: Native rule to enforce a minimum count of non-whitespace characters #60331
Unanswered
skpassegna
asked this question in
Ideas
Replies: 1 comment 4 replies
-
|
Would you only add this or a group of rules (similar to password policies): 'description' => ['required', 'chars:4', 'punct:1', 'nums:3'],
// or
'description' => ['required', Rule::ctype()->chars(4)->punct(1)->nums(3)], |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Laravel currently has no built-in validation rule that enforces a minimum number of meaningful (non-whitespace, non-punctuation) characters in a string field. The closest combination a developer would naturally reach for is:
This looks like it should guarantee at least 10 real characters of content. It does not.
Reproduction
Given the rules above, the following input passes validation:
The pipeline processes it as:
TrimStringsmiddleware strips leading/trailing whitespace →". . . ."requiredpasses — the value is not null or emptymin:10passes — the trimmed string is 13 characters longstringpasses — it is a stringThe value stored is
". . . ."— content that carries no meaning in any real-world textarea (comment box, description field, message field).Why this is not a
min/maxbugmin/maxcounts raw string length. That is correct and documented behavior.requiredchecks for null/empty. Also correct.The gap is that no native rule exists to express: "this field must contain at least N characters that are not whitespace or punctuation."
A developer can work around this today with regex or a custom Rule class, but the combination
requiredmin/max:Nstringcreates a false sense of security that the common case is covered. It is not.Proposed rule
A new rule —
char:N— that counts only Unicode letter/digit characters (\pL\pN) after stripping everything else:Implementation would be straightforward:
Why this belongs in the framework
This is not a niche use case. Any
<textarea>for comments, descriptions, reviews, or messages faces this exact gap. The fix requires framework awareness because the appropriate rule name, error message translation key, and documentation entry all need to exist first-party to be discoverable.I apologize for any English error in my text.
Beta Was this translation helpful? Give feedback.
All reactions