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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Validate very strong password
Expression
^(?=^.{8,}$)(?=.*\d)(?=.*\W+)(?=.*[a-z])(?=.*[A-Z])(?i-msnx:(?!.*pass|.*password|.*word|.*god|.*\s))(?!^.*\n).*$
Description
This regular expression can be used to validate a strong password. It will evaluate to true if the following critera are met: Must be 8 characters in length total. Must contain at least 1 digit. Must contain at least 1 lower case letter. Must contain at least 1 upper case letter. Must contain at least 1 non-character (such as !,#,%,@, etc). Must not contain the words "password" or "pass" or "word" or "god" Must not contain a whitespace. Note: This version is not compatible with JavaScript
Matches
one2!fouR, @Eight21, one22Four%, 2thRee@four, 7diPity*, 12345aB(
Non-Matches
one2three!, four2345, #viced@#$, short1@
Author Rating: The rating for this expression. Charles Forsyth
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: Nice start, but
Name: Cecil
Date: 5/3/2012 11:27:02 AM
Comment:
will only work in English culture. Most languages (even those without a completely non-latin alphabet) have more upper and lower case letters. Diacritics (ö, ä, ü, å, é, è, ...) in other cultures are normal letters, but in your regex they are not considered to exist at all (not even special ones).


Title: Nice job; a few ideas for you
Name: Speednet
Date: 7/25/2008 5:14:15 PM
Comment:
Good job overall. Here are some comments: 1. If you're checking for "pass", there is no need to also check for "password" (take out "|.*password"). 2. Correct your description to say "Must be 8 characters in length..." (not 15). 3. Remove the first look-ahead for the length. (Remove the "(?=^.{8,}$)".) You can do it in a single check at the end (see #5). 4, Remove the plus sign after \W. (Just need to match one.) 5. Rather than just checking for "\n", I'd recommend a simpler way that protects against ALL undesireable characters, not just a newline. Remove the ending of "(?!^.*\n).*$", and replace it with "[\x20-\x7e]{8,}$". It ensures that all characters are between ASCII codes 32 and 126, as well as doing the length check for at least 8 characters. If you don't want to allow spaces, make it \x21-\x7e. So the entire thing should be: ^(?=.*\d)(?=.*\W)(?=.*[a-z])(?=.*[A-Z])(?i-msnx:(?!.*pass|.*word|.*god))[\x20-\x7e]{8,}$


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