Possible Duplicate:
Password validation (regex?)
I am working on asp.net MVC 3 application and I have applied
[Required] [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Password")] public string Password { get; set; }
DataAnnotation to my Password field. I want to make sure that password must be at least 6 characters, no more than 18 characters, and must include at least one upper case letter, one lower case letter, and one numeric digit. Do I need to add regular expression or DataType.password will do all this ?
Please suggest
Data Annotation to validate confirm password.
1. Required Data Annotation attribute. Both the Password and the ConfirmPassword properties has been applied with the Required Data Annotation attributes. The Required Data Annotation attribute have been specified with a property Error Message with a string value.
We can easily add validation to our application by adding Data Annotations to our model classes. Data Annotations allow us to describe the rules we want applied to our model properties, and ASP.NET MVC will take care of enforcing them and displaying appropriate messages to our users.
When creating users in MVC application want users to enter strong password and re-enter password to confirm. Add DataAnnotations namespace to login class. DataAnnotations have Compare attribute. [Compare("Password", ErrorMessage = "Confirm password doesn't match, Type again !")]
You must write exactly what you want. Write this:
[Required] [StringLength(18, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [RegularExpression(@"^((?=.*[a-z])(?=.*[A-Z])(?=.*\d)).+$")] [DataType(DataType.Password)] [Display(Name = "Password")] public string Password { get; set; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With