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
use this ^(?=. ?[#?!@$%^& -]).{8,}$
you can see the details here
你可以试试这个。
/(.{7,}(?=[#?!@$%^&*-])|(?=[#?!@$%^&*-]).{7,})/
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...';
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.