-7

I Tried to validate a statement with below regular expression, In some of the cases it is working as expected but not in the other cases.

/^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{12,20}$/

passed scenario's

test@Test123

Failed Scenario's

test.Test123

In this scenario we can allow alphanumeric,at least one special character and length should be in between to 20 characters.

Narendra Manam
  • 161
  • 3
  • 11
  • Please read [How to ask](https://stackoverflow.com/help/asking) before asking any more questions. Unless you ask a question that can be answered you cannot expect to get any meaningful answers. – jwpfox Jan 04 '18 at 13:11
  • Show us what you have tried. Stackoverflow isn't a free code writing service.With a little bit of research you should be able to get most of this, if not all figured out and when you have actual code that isn't working ask questions – charlietfl Jan 04 '18 at 13:12
  • I forgot to include, Now I added in the question – Narendra Manam Jan 04 '18 at 13:13
  • Read `How to create a Minimal, Complete, and Verifiable example` at the link I gave you. Provide a MCVE if you want meaningful help. – jwpfox Jan 04 '18 at 13:14
  • Just add the `.<>` character inside the character class `[A-Za-z\d$@$!%*#?&.<>]` – Toto Jan 04 '18 at 13:16
  • I tried `[A-Za-z\d$@$!%*#?&.<>]` this, But it is not working – Narendra Manam Jan 04 '18 at 13:23
  • Possible duplicate of [javascript regex for password containing at least 8 characters, 1 number, 1 upper and 1 lowercase](https://stackoverflow.com/questions/14850553/javascript-regex-for-password-containing-at-least-8-characters-1-number-1-uppe) – ctwheels Jan 04 '18 at 14:15
  • Also, don't do this client-side. It's a bad idea. Also, don't limit the password to specific characters, you're making your system **extremely vulnerable** the way you're coding it. – ctwheels Jan 04 '18 at 14:16

1 Answers1

0

Though,the question was duplicate.

Answer for your question: This pattern will help you to validate:

/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^\w\s]).{8,}$/

At least --one upper case English letter --one lower case English letter --one digit --one special character --Minimum eight in length