Regularexpression only letters in the Model

Asked

Viewed 735 times

2

Using the following Regularexpression in the Model:

[RegularExpression(@"^\d+$")]
public int ano_da_configuracao { get; set; }

I get the following result:

inserir a descrição da imagem aqui

I tried as follows to accept only letters:

[RegularExpression(@"/^[A-ZÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ ]+$/")]

thinking that it could achieve the same result, but it didn’t work.

How to fix this expression so it works as the first example?

  • Have you tried [RegularExpression(@"^\w+$")]?

  • @Gypsy Morrison Mendez It didn’t work continues accepting numbers. html is like this: data-val-regex="O campo UF deve corresponder à expressão regular '^\w+$'." data-val-regex-pattern="^\w+$" .

  • tried to use the D?

1 answer

2


The right thing would be:

[RegularExpression(@"^[a-zA-Z]+$", ErrorMessage = "Use apenas caracteres alfabéticos.")]
public String MinhaString { get; set; }
  • That’s right! Thanks again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.