Solved

Help (Password)

Posted on 2012-03-13
2
293 Views
Last Modified: 2012-03-21
Hi,

I am new to MVC  and I am not sure how to do this.

I have a textbox for New password.  the new password should include at least one number,
one Upper case letter, one lower case letter and one special character.

Thank you for helping me.

here's the code

[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "New password")]
public string NewPassword { get; set; }
0
Comment
Question by:lulu50
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
ambience earned 500 total points
ID: 37718865
I believe can be done using a RegularExpression

[RegularExpression(@"(?=\d)(?=[a-z])(?=[A-Z])(?=[\!\@\^\$])^([a-zA-Z0-9\!\@\^\$]{4})$")]
public string NewPassword { get; set; }

BTW, this is the basic idea and it may take some tweaking before getting it right.

Here is what the expression does

(?=\d)         # Lookahead for string that has at least one digit
(?=[a-z])     # Lookahead for string that has at least lowercase letter
(?=[A-Z])
(?=[\!\@\^\$])  # Lookahead for string that has some special char (Add others you want to allow)
^([a-zA-Z0-9\!\@\^\$]+)$ # Finally the pattern to match

The first four lookaheads are used to ensure presence of specified patterns without consuming input. The last part is a simple regular expression.

Hope that helps ..
0
 

Author Closing Comment

by:lulu50
ID: 37746823
Thank you
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question