Validation with ASP MVC

Asked

Viewed 60 times

0

Personal I am in trouble, precise that the attribute code (from my database) has either have position greater than 4 numbers and with attribute value can not contain value less than 0.

I tried to use [Stringlength(4)] however when it executes the error because it can only use character ,I looked for some solutions but so far nothing. inserir a descrição da imagem aqui

  • 3

    Hello Robson, welcome to Stack Overflow in English. To better understand, could you put the code instead of the image? Which version of [tag:Asp.net-mvc] are you using? Taking advantage, there is [tour]. Stop by when you have time to get a better understanding of the site :p

  • Thanks for the help,my version is the ASP MVC 5 ,I will take a look yes.

1 answer

0

[MinLength(4, ErrorMessage = "O campo {0} deve ter no mínimo {1} caracteres")]
  • In case on minlength you put 5.

  • Thanks man, it worked out and imagine it was just that hahahhaha

  • Only then this error appeared ,System.Invalidcastexception: It is not possible to convert an object of type 'System.Int32' in type 'System.Array'.

  • You want the code to have at least four digits is that? Does the value have to be at least 4? What you can do is create a partial class because by doing it on tt itself you will lose what you typed. Automatically generated files with T4 are deleted when generating again. You can create a class by part and then add a string property to it. Or use a regular expression:

  • I got, thank you very much I used this Regular Expression( @" d{4}$")

  • Please collaborate with the quality of community content by better elaborating your response. Very short answers will hardly be clear enough to add anything to the discussion. If your response is based on some function or feature of the language/tool, link to the official documentation or reliable material that supports your response. Searching for similar questions in the community can also be interesting to indicate other approaches to the problem.

  • OK thanks @Andersoncarloswoss

Show 2 more comments

Browser other questions tagged

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