Michael Drum Michael Drum - 4 months ago 44
Javascript Question

How do I check if a string contains at least one number, letter, and character that is neither a number or letter?

The language is javascript.

Strings that would pass:


Pu54 325


Strings that would not pass:



I tried the following:

var matches = password.match(/\d+/g);
if(matches != null)
//password contains a number
//check to see if string contains a letter
//string contains a letter and a number


You can use Regex:

I took it from here: Regex for Password

var checkPassword(password){
    return !!password.match(/(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{3,}$/);

I use this Regex:

Minimum 3 characters at least 1 Alphabet, 1 Number and 1 Special Character: