I am using data annotation for model recognition in MVC4 and currently using StringLengthAttribute, but I I do not want to specify the maximum value (currently set to 50) but want to specify a minimum string length value.
Is there any way to specify only a minimum length? Maybe I can use another feature?
My current code is:
[required] [datatype (datatype password)] [display (name = "confirm new password"]] [string lang (50, minimum length = 7)] (compare ("newpassword", error message = "new password and confirm that no new password has been matched.")] Public String Confirm Newpassword {get; set;} < / Code> Any help is greatly appreciated.
Only Is there a way to specify a minimum length? Maybe I can use another feature?
Using standard data annotations, No. You must specify maximum length Only other parameters are optional. In this situation, I give some suggestions like this:
[string lang (int.MaxValue, MinimalLength = 7)] You can also use a Regex (regular expression) feature as (Regular expression: ("? ^ (?:. * [Az]) {7,} $", error message = "the length of the string should be greater than or equal to 7 characters . ")]
More here on:
Comments
Post a Comment