Problem with special characters in password meter

Asked

Viewed 90 times

0

Next, I got a password strength meter that even works. Except he has a bug that I don’t know what the hell happens that I can’t fix at all. To validate, you need to type 8 characters, 1 uppercase letter, 1 number and 1 special character. He has a "check" type that will mark if you put all this information. The problem is that for example, if I start the password with a special character, it does not mark as accepted, it will only mark as accepted if I put in the end or middle of the password. I don’t know why this happens. The code is here: https://jsfiddle.net/danielswater/vw028uk9/2/

Anyone who can help me, I’d really appreciate it

1 answer

1

Daniel, in the special character regex, there is a dot (.), expecting "any" character before special character class:

if ( a.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) {

To fix, just remove that point:

if ( a.match(/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) {

With this, it starts to validate the special character typed in any part of the password.


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

  • Man, you can only be an angel kkkkkkkkkkkkk. Thank you very much man, you have no idea how much you helped

Browser other questions tagged

You are not signed in. Login or sign up in order to post.