I need to check that a string input contains exactly 2 special characters and 1 number.
is this the correct regex for this job?
(?=(.*[`!@#$%^&*-_=+'/.,]){2})
this is only checking special characters and not numbers.
I tried the regex above and it is not checking numbers
2
Answers
Please find below your regex:
(?=.*[!@#$%^&*()-=_+{}[]|\;:'",.<>/?])
asserts that there is at least one special character present, and(?=.*d)
asserts that there is at least one digit present. The rest of the regular expression ensures that there are exactly 2 special characters and 1 number present in the string.You can use this instead:
and here is the test case to test the regex as per your requirement.
I hope it works for you!