Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 1st, 2006, 01:46 PM
Registered User
Join Date: Mar 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Regualr Expression Password Matching

Is there a way in one single Reg Expression to validate a password string that satisfies,

1. Must have at least one upper case letter [A-Z]
2. Must have at least one lower case letter [a-z]
3. Must have at least one number [0-9]
4. Must have at least one special character from [! $ % ^ & * ( ) _ + = < > ? / \ | ] [ { }]
5. The string length should be between 6 and 25.

Note: The above said steps 1-4 characters can appear in any random order.

I have a solution, but the problem with this one is, I have to check for each named group,

In C# code I would check as,

if (aMatch.Success && aMatch.Groups["lower"].Success
&& aMatch.Groups["upper"].Success && aMatch.Groups["number"].Success
&& aMatch.Groups["symbol"].Success)
Valid Password;
Not valid;

Is there a better solution, such as writing the whole thing in one Reg Expression?


Reply With Quote
  #2 (permalink)  
Old March 24th, 2006, 08:32 PM
Registered User
Join Date: Mar 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

The Regular Expression engine is fairly fast, so defining your RegEx string that satisfies your requirements is the way I would go. Here's an example RegEx string which would satisfy most of your conditions using RegEx.IsMatch(inputstring, regexstring):

My regexstring sample:


Note that I only used the underscore special character, but you can simply insert any number of special characters you want (escpaing out the characters where necessary).

I've tested the string out with RegEx Buddy for the following input strings:


All of them matched up successfully.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression matching sub string mayasht Pro Java 3 August 8th, 2007 05:32 AM
Regular expression to select non-matching pattern Neuron BOOK: Beginning Regular Expressions 1 June 12th, 2006 10:06 AM
Regualr Expression Password Matching Chandra Paladugu C# 1 March 2nd, 2006 04:47 PM
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

All times are GMT -4. The time now is 04:21 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.