-1
This is my validation:
[Required(ErrorMessage = "O nome completo é obrigatório.", AllowEmptyStrings = false)]
[RegularExpression(@"^[a-zA-ZáàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ''-'\s]*[a-zA-ZáàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ]+$", ErrorMessage = "Números e caracteres especiais não são permitidos no nome.")]
[StringLength(50, MinimumLength = 1, ErrorMessage = "Limite máximo de 50 caracteres e limite minimo de 1 caracteres")]
public string Nome { get; set; }
But in the results it saves for example
Ana julia
The problem is you’re saving too:
Ana julia
That is, it is allowing many spaces, wanted a solution that left only one space.
because you don’t include in regex for it to filter more than two spaces?
– Lucas Miranda
how ? does it friend
– Guilherme silva
Take off the
\s
from within the brackets, and leave only one space between the sequences of letters:^[a-zA-ZáàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ''-']+( [a-zA-ZáàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ]+)*$
- of course she’s still a naive regex, because she accepts names that start withÇ
, for example. A more precise regex, however, would be extremely complex, then perhaps it is better to create a custom attribute– hkotsubo
thanks for the tip, but the regex didn’t work
– Guilherme silva