Email verification with simple verification is not the same client as serveride

I use FluentValidation to test my models on both the client and server side. I am in the latest version:

FluentValidation.MVC5

at the time of writing which

5.5.0.0

I have the following validator simplified:

public class MyViewModelValidator : AbstractValidator<MyViewModel>
    {
        public MyViewModelValidator()
        {
                RuleFor(x => x.Email)
                    .EmailAddress().WithLocalizedMessage(() => MyResources.Validation_Email_NotValidAddress)
                    .NotEmpty()
                    .WithLocalizedMessage(() => MyResources.Validation_Email);
        }
    }

The client side seems to perform some basic verification, for example, that it will not accept anything without text on both sides of the "@" character, however it will accept something like test@test.

The problem occurs when I send this data, I have the following in the controller:

    if (!ModelState.IsValid)
        throw new Exception("Model validation error");

This means that the model is invalid due to the email address test@testand throws an error. Therefore, it seems that my front-side validation is weaker than my server-side validation.

, , Email() , , , , .

https://fluentvalidation.codeplex.com/wikipage?title=mvc

, , .

+4
2

, Matches, , .

   RuleFor(x => x.Email)
                .Matches(@"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$").WithLocalizedMessage(() => MyResources.Validation_Email_NotValidAddress)              
                .NotEmpty() // <-- and cant be empty
                .WithLocalizedMessage(() => MyResources.Validation_Email);

Regex, , ASP.NET RegularExpressionValidator. .

0

( data-val-email), jquery.validate plugin core ( "email", RegExp)

, Fluent Validation EmailValidator ( RegExp)

: / , - , /. - EmailAddress() Match() regexp, .

:

- ,

+1

Source: https://habr.com/ru/post/1617594/


All Articles