-1

I need a regular expression to validate a password containing at least 8 characters, must include at least one uppercase letter and a lowercase letter. And must specifically include one of the following symbols @,#,%,^,&,*,)

i havent been able to find one that would include only those ascii characters.

thanks in advance for your help!

  • You should search at least the similar questions like [this one](http://stackoverflow.com/questions/2370015/regular-expression-for-password-validation?rq=1) and also post what you have tried already so someone can point in the right direction since SO is a website intended to be a help site, not a database of solutions for specific problems. – Bikonja Apr 03 '14 at 20:14
  • This is a great website to test regular expressions http://regexr.com/ – gonzalovazzquez Apr 03 '14 at 20:16

2 Answers2

2
 /^(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*]).{8,}$/

Regular expression to assert a password that must contain atleast one Smallcase ,Capitalcase alphabet and a Special character(!@#$%^&*). Can increase the max length of password from 20 to more.

Bharathvaj Ganesan
  • 3,054
  • 1
  • 18
  • 32
Arvind
  • 2,525
  • 1
  • 13
  • 21
  • shouldnt it start with /^\ and end with an /? this didnt work for me – user2309306 Apr 03 '14 at 21:40
  • Yes, Its just regular exp pattern and u need to add \ and / at end and front. works here- http://regexr.com/ – Arvind Apr 04 '14 at 05:13
  • Two minor nitpicks -- no mention of needing a digit in the question, and also you can use `{8,}` to avoid having to specify an upper-bound. – ach Apr 04 '14 at 13:38
1

You can also put all your validation regex's in an array and then use every.

var atLeastLowerCase = /[a-z]/; 
var atLeastUpperCase = /[A-Z]/;
var atLeastSpecial = /[\@\#\%\^\&\*\]\)]/;
var password = "somePass@";
var passes = [atLeast8,atLeastLowerCase,atLeastUpperCase,atLeastSpecial].every(function(a){
   return a.test(password);
}) && password.length>=8;
if(passes){
   //do something
}else{
   //do something else
}
Patrick Evans
  • 41,991
  • 6
  • 74
  • 87