Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help (Password)

Posted on 2012-03-13
2
Medium Priority
?
295 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

715 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