0

looking to validate a password, currently i have

var myRegularExpression = /(?=.*?[#?!@$%^&*-]).{8,}/ ;

am i missing something? it can contain anything but the only requirements it must have are at least 1 special character and be greater than 8 characters

  • Possible duplicate of [Using a regular expression to validate an email address](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address) – bestbballplayer Dec 04 '16 at 06:20

3 Answers3

0

use this ^(?=.?[#?!@$%^&-]).{8,}$

you can see the details here

Vinod Louis
  • 4,812
  • 1
  • 25
  • 46
0

You can try this one.

/(.{7,}(?=[#?!@$%^&*-])|(?=[#?!@$%^&*-]).{7,})/
tomasran
  • 31
  • 5
0

This function can be used. Pass in a the password string to test it. If it is longer than 8 characters i will get tested by the RegEx test to see if there is a special character. If there is a special character it returns true if there is none them the "Password is either....." text is returned.

function passWrdTest(str){
    var myReg = /\[|\#|\?|\!|\@|\$|\%|\^|\&|\*|\-|\]/g;
    return str.length > 8 ? myReg.test(str) : 'Password is either not long enough or does not have a special character...';
}
andre mcgruder
  • 1,120
  • 1
  • 9
  • 12