regex - Javascript regexp character matching -


i'm looking using jquery password strength indicator , have found 1 looks suitable.

it increases password strength score if special characters detected:

if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)){ score += 5 ;} 

however i'd able specify additional special characters , because these lists of special characters used in several places, i'd specify list once:

list = array(!,@,#,$,%,^,&,*,?,_,~,[,],{,},(,)); if (password.match(/(.*[list].*[list])/)){ score += 5 ;} 

is possible?

you can use strings:

var special = "!@#$%^&*?_~[]{}()".split('').join('\\'); if (password.match(new regexp("(.*[" + special + "].*[" + special + "])")))... 

(the join-with-backslashes escapes special characters treated literally regex engine.)


Comments