Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help (Password)

Posted on 2012-03-13
2
Medium Priority
?
299 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
2 Comments
 
LVL 22

Accepted Solution

by:
ambience earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

886 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