Skip to content

Optional fields with whitespace values still produce unclear validation errors #1348

Description

@KavyashreeSN

I noticed that there was a previously closed issue related to optional fields
and whitespace handling.

However, in current versions of express-validator, when optional() is used
together with validation chains (e.g. isInt()), fields that contain only
whitespace can still produce validation errors with messages that are not
clear for API developers.

This seems especially confusing when sanitizers like trim() are used before
or after optional().

Example:
body('age').optional().trim().isInt()

If the client sends:
age=" "

The resulting validation error does not clearly explain why the value was
considered invalid, even though the field is optional.

This is a common real-world API scenario. Improving error clarity or behavior
here would help developers avoid confusion.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions