Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 20th, 2004, 11:32 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default Regular Expression for a password?

I'm terrible at regular expressions. Can anyone help me?

I need to verify that a string contains at least one uppercase character, at least one lower case character, and at least one digit. It may contain more; these are minimum requirements. These required characters may be in any order in the source string.

Is there a single regular expression that will verify this? Obviously I can do it with three separate REs and then combine their results, but I'd like to do it all at once if possible.

Thanks for any help anyone can give.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
__________________
-- Jeff
 
Old January 20th, 2004, 09:47 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Jeff,

I've been brewing this in the back of my head since your post and I can't come up with anything useful. Every idea I have ends up being an OR condition. The only thing I could come up with was to build a big complex regex that has all six combination of character sequences (allowing for characters in between). I think you are probably better off just using three, as much as that stinks.

Peter
 
Old January 21st, 2004, 06:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Jeff, I can reduce it to 2 REs with this one that verifies its not all uppercase and not all lowercase
(?!^[a-z]*$)(?!^[A-Z]*$)^[a-zA-Z0-9]+$

but I can't get the number test in there too, because a number is not upper or lower case.

Maybe someone else can add to it?

hth
Phil
 
Old January 21st, 2004, 06:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Jeff, just found a likely candidate. try this one it should do it all in one go.
^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$

(original is at http://www.regexlib.com/REDetails.aspx?regexp_id=31)

rgds
Phil
 
Old January 21st, 2004, 06:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hang on, just discovered that the previous one allows spaces, so try this instead:
^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).*$
 
Old January 21st, 2004, 01:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

That seems to do the trick - thanks.

And thanks for the URL - that looks like it will be quite useful from time to time.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old May 18th, 2007, 10:59 AM
Registered User
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Guys - can you help me with this? I've taken the regexp above and tried to extend it so that it requires:

at least one lowercase
at least one uppercase
at least one of a number OR a symbol
at least 6-12 characters

^(?=.*(\d|[^a-zA-Z]))(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{6,12}$

But my 'regexp' checker isn't liking it. Any ideas what is wrong with it?

Cheers,
Daniel






Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular expression for password? tina123 ASP.NET 1.0 and 1.1 Basics 2 October 3rd, 2008 08:23 PM
Regular Expression Help Please rstelma ASP.NET 1.0 and 1.1 Professional 0 January 2nd, 2008 07:01 PM
Password Validation with Regular Expression moghazali ASP.NET 1.0 and 1.1 Basics 0 January 7th, 2007 04:50 AM
Regular Expression for password kitkits ASP.NET 1.0 and 1.1 Basics 2 April 28th, 2005 11:44 PM
Regular Expression for password Baby_programmer ASP.NET 1.0 and 1.1 Basics 1 December 28th, 2004 01:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.