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?

1

2 Answers 2

1

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

const pattern = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]*$/;
Sign up to request clarification or add additional context in comments.

Comments

0

try to use this function

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.