Validation with Jquery in mvc fields [duplicate]

0

I have a View with some fields, I need to do a validation to check if the field is empty when the user clicks on a button eg save, search for some functions in jQuery no more answers what I need to do, someone knows a jQuery function which validates all fields of a view without having to enter the field name eg:

Nome :{
        required : true
 }

I would like an example where the function is generic, where I can use only once for various fields.

    
asked by anonymous 03.04.2014 / 21:38

2 answers

2

jQuery Validate can help you. It is possible to validate a myriad of things very easily. If you have any difficulties you can leave an issue in the repository, I am the maintainer and can help you with more complex doubts.

It has simple uses for validation like this:

<input type="text" data-required />

Or:

<input type="text" data-pattern="^\d+$">
    
03.04.2014 / 22:25
1

If you are using the ASP.NET MVC you can decorate your properties with [Required(Errormessage = "Campo obrigatório")] that the framework itself says, as long as the jquery validity is loaded at the time needed for validation.

In your view you should put @Html.ValidationMessageFor(e => e.Propriedade) to get the message red.

    
03.04.2014 / 21:58