RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{4,8}$
Description
Password expresion that requires one lower case letter, one upper case letter, one digit, 6-13 length, and no spaces. This is merely an extension of a previously posted expression by Steven Smith ([email protected]) . The no spaces is new.
Matches
1agdA*$# | 1agdA*$# | 1agdA*$#
Non-Matches
wyrn%@*&$# f | mbndkfh782 | BNfhjdhfjd&*)%#$)
Author Rating: The rating for this expression. Jeremy Samuel
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: starts with a number
Name: Andre
Date: 1/31/2008 5:01:08 PM
Comment:
Not sure if this is specific to Visual studio and the regularexpression control but i can't get it to validate unless the password starts with the number. I realize it works in this site's test harness, but just looking for some insight and if this is happening to anyone else.


Title: starts with a number
Name: Andre
Date: 1/31/2008 4:58:57 PM
Comment:
Not sure if this is specific to Visual studio and the regularexpression control but i can't get it to validate unless the password starts with the number. I realize it works in this site's test harness, but just looking for some insight and if this is happening to anyone else.


Title: Very Very Helpful. I had to escape the \
Name: Raj P
Date: 1/24/2006 11:21:25 AM
Comment:
I really want to thank Jeremy for saving me a lot of pain to come up with this. I just had to escape the \ in the expression with another \ as I got "unknown escape code" error. My code is boolean retval=false; String passwordPattern = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\\s).{8,15}$"; retval = password.matches(passwordPattern); Thanks again Raj


Title: No match?
Name: Javier
Date: 12/14/2005 2:00:36 PM
Comment:
Thanks Jeremy, No match for "aB123" JavaScript client validation. I did something wrong? Using IE... JavaScript version 5.6.8513


Title: Length
Name: Panso
Date: 8/28/2005 10:04:23 PM
Comment:
Great, works a charm except the length is set to 4-8 chars change the end to {6,13}$ and it does what it says on the tin. Simple, and probalby so obvious that most fixed it without a mention. I am a complete newbie with regex, so I banged my head against my screen till i realised. Saving othet idiots like me the hassle ;) Thanks.


Title: Two Digits
Name: Candi Suriano
Date: 4/27/2005 4:21:37 PM
Comment:
This is close to what I need, but I need two digits not just one. I can't seem to figure out how to get that second digit if it's not consecutive.


Title: Expression of gratitude
Name: Neil Walls
Date: 4/6/2005 10:45:25 PM
Comment:
Thanks Jeremy, I figured how Positive and Negative lookahead work from analysing your code. I adapted your expression to accept only alphanumeric characters and to accept either/or upper/lower case ^(?=.*\d)(?=.*[a-zA-Z])[a-zA-Z\d]{5,15}$ This regex stuff looked like greek initially but is surprisingly easy to get the hang of, well the basic stuff I need anyhow....


Title: Re: Strange Issue
Name: Michael Ash
Date: 4/6/2005 10:29:19 AM
Comment:
Most likely you tested with the case insensitivity turned on. Doesn't pass otherwise.


Title: Strange Issue
Name: Christopher Blickley
Date: 4/5/2005 4:23:23 PM
Comment:
I might be missing something, but why does this pass the expression? 123098cb Since it doesn't include an uppercase, shouldn't it fail? The "test" mechanism on this website lets it go through.


Title: If I want to have spaces?
Name: Vadim
Date: 3/25/2005 5:10:36 AM
Comment:
Hi Jeremy! Your pattern is more suitable for me but except one thing - I need to have spaces How to change the pattern to have spaces? Thanks


Title: Answer to Eric Johnson
Name: someone else
Date: 11/17/2004 12:26:24 PM
Comment:
I don't know if I understood you right, but try this one: (?!.*(.)\1{2,})


Title: Very helpful... I'd like to add something else
Name: Eric Johnson
Date: 9/24/2004 2:08:06 PM
Comment:
Jeremy, This is very close to what I'm trying to accomplish in a RegExValidator control for password entry. I'd like to add a condition to disallow a substring that contains more than 2 consecutive occurences of the same character. I've seen regexp_id # 460 but so far I can't make the inverse work from within an expression. I tried (?!((.)\1{2,})) and a few variations without any luck. Any help would be great.


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials