You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Masked validator decorates other validators to mask sensitive input
values in error messages while still validating the original unmasked
data.
This validator is essential for applications handling sensitive
information such as passwords, credit cards, or email addresses. Without
it, users would need to implement a custom layer between Validation and
the end user to prevent PII from appearing in error messages or logs.
With Masked, sensitive data protection is built directly into the
validation workflow with no additional abstraction required.
Assisted-by: Claude Code (Opus 4.5)
// → "41111XXXXXXX1211" must be a valid credit card number
26
+
```
27
+
28
+
This validator is useful for security-sensitive applications where error messages should not expose sensitive data like credit card numbers, passwords, or email addresses.
29
+
30
+
It uses [request/string-formatter](https://github.com/Respect/StringFormatter) as the underlying masking engine. See the section the documentation of [MaskFormatter](https://github.com/Respect/StringFormatter/blob/main/docs/MaskFormatter.md) for more information.
31
+
32
+
## Categorization
33
+
34
+
- Cosmetic
35
+
- Miscellaneous
36
+
37
+
## Behavior
38
+
39
+
The validator first ensures the input is a valid string using `StringVal`. If the input passes string validation, it validates the original unmasked input using the inner validator. If validation fails, it applies masking to the input value shown in error messages.
40
+
41
+
## Important Notes
42
+
43
+
-**Positions are 1-based**: Position `1` refers to the first character, not position `0`
44
+
-**Empty ranges mask everything**: `range = ''` defaults to masking the entire string
45
+
-**Range end is exclusive**: `1-@` masks up to (but not including) the `@` character
46
+
-**Duplicate positions**: Repeated ranges in the specification are automatically handled
0 commit comments