I am learning MVC (version 5) by doing a sample project. Hence I am not using any scaffolding and doing everything from scratch. I have a View Model, which has a Password field with the following validations.
[Display(Name = "Password")]
[DataType(DataType.Password)]
[Required(ErrorMessage = "{0} is Required.")]
[Range(1, 4, ErrorMessage = "{0} has to be between {1} and {2} characters.")]
public string Password { get; set; }
Now in my .cshtml, I have a password textbox rendered using @Html.EditorFor. Since I am learning, I don't have any css added. I have added references to jquery-1.10.2.js, jquery.validate.js and jquery.validate.unobstrusive.js in the cshtml file. The validations are working properly, except for the above password field. If I enter only 1 character in the password textbox, validation passes, whereas anything more than that fails, which is strange. I am not able to understand this. Can anyone please help me with this?
rangeis for numbers, not length of strings. Also, the question is really about how to properly use the Unobtrusive Validation plugin as part of ASP, not the underlying jQuery Validate. Edited tags.