1

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?

Gridnev
  • 21
  • 3
  • 1
    First you are missing quantifier, second characters you have provided do not match `A-Z`. Check https://stackoverflow.com/questions/6067592/regular-expression-to-match-only-alphabetic-characters – Jan Pfeifer Jan 30 '23 at 14:08

2 Answers2

1

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

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

try to use this function

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