Skip to content

Required validator differs from MVC validation in allowing bypass by using spaces in value. #109

Description

@RyanONeill1970

Using a 'required' validator such as below, I'm able to get past the validation by just entering a space (or multiple spaces).

This differs from the default jQuery MVC + Unobtrusive behaviour where spaces are treated as an empty string and fail validation.

<input data-val="true" data-val-required="Field cannot be blank." id="FieldName" name="FieldName" type="text" />

I think it is this line;

  return Boolean(value);

Which could be reworked as;

  return Boolean(value?.trim());

Link to source;

https://github.com/haacked/aspnet-client-validation/blob/062c8433f6c696bc41cd5d6811c840905c63bc9c/src/index.ts#L151C1-L151C31

I can do a pull request if you agree that it's correct.

Thanks both of you for your work on this.

Ryan

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions