Solved

Help (Password)

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now