Gridnev
Gridnev

Reputation: 21

regex for password (js)

I have a password string. I need my password to be only Latin, symbols, numbers. It doesn't have to be all together. I wrote this:

const pattern = /[a-zA-Z0-9!@#$%^&*]/g;
if (!pattern.test(value)) {
    return 'ERROR';
}

The problem is that if I write the password: "фыва", then the validation doesn't pass the password, and if I write "фыва1", then it does. What am I doing wrong?

What regex expression should I write?

Upvotes: 1

Views: 40

Answers (2)

Gridnev
Gridnev

Reputation: 21

Thanks to all. This regex helped me to cope with the problem.

const pattern = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]*$/;

Upvotes: 1

Yassin Mo
Yassin Mo

Reputation: 600

try to use this function

var regularExpression  = /^[a-zA-Z0-9!@#$%^&*]$/;

Upvotes: 0

Related Questions