Validation regex does not work


If I use regex like this one:
userForm.setValidation('password', '[0-9]+' );
it validates fine, but I want to use my regex, like:
userForm.setValidation('password', '/^(?=.*\d)(?=.*[!@#$%^&*])(?=.*[a-z])(?=.*[A-Z]).{8,20}$/' );
and it does not validate.
The regex itself looks fine, you check it here:
For example string ‘asd345DD!’ will be valid.

What could be the problem here?

Please, try to use the validation implemented in a function as a workaround:

function passVal(val){
const re = new RegExp('^(?=.*\d)(?=.*[!@#$%^&*])(?=.*[a-z])(?=.*[A-Z]).{8,20}$');
return re.test(val)
myForm.setValidation('password', passVal );