-2

I want a regex that should only match if the string contains minimum 10 to 16 characters with atleast, a number, a string, an uppercase, a lowercase character and a special character.

I think this string should pass this regexp test but this is not working : The String does not include the apostrpohes' or quotes. String : 'asdf@A1234';

Regexp: /^(?=.*[0-9])(?=.*[!@#$%^&*])(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9!@#$%^&*]{10,16}$/; Can someone kindly suggest what I am missing?

function testpwd(pwd) {
                var re = /^(?=.*[0-9])(?=.*[!@#$%^&*])(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9!@#$%^&*]{10,16}$/;
             console.log(" Test Result is " + re.test(pwd) )
                return re.test(pwd);
            }

Update Sorry for the red flag Guys. The code is working. The error was somewhere else :). I am rephrasing the question so that It can be of some use for future visitors.

Ramesh Pareek
  • 1,601
  • 3
  • 30
  • 55

2 Answers2

2

It does appear to work, https://regex101.com/r/2u0jZ2/1

Without the quotes and semi colon though. If the quotes and semi colon are part of the string, then that's the reason the match isn't happening

Denno
  • 2,020
  • 3
  • 19
  • 27
0

this is a strong regex accept 14 numbers and capital letter small leter all symbols in keyboard start /(?=[A-Za-z0-9@#$%^&+!?=.()_-~/-]+$)^(?=.[a-z])(?=.[A-Z])(?=.[0-9])(?=.[@#$^&+!=])(?=.{14,}).$/ end