Solved

Help (Password)

Posted on 2012-03-13
2
290 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 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 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