To check whether it contains a character from either string, you can use Javascript Regular Expressions. Just match your password candidate to those characters as per the link. You are going to try for four matches. The length of the string, you can check in its length
property.