2

could someone pleas help me , I need an expression for a password for fulfill the following criteria:

  • at least 8 characters length to a maximum of 15 characters.
  • at least one letter in upper Case.
  • at least one letter in lower Case.
  • at least 1 special character.
  • at least 1 numeral.

These must be acceptable in any order if possible.

This is an attempt i found but doesn't fulfill the criteria above,i have tried modification but my problem rests in having these in any order and at least one of any of the characters specified ,i have tried reducing each expression below to suit also :

^(?=.*[A-Z].*[A-Z])(?=.*[!@#$&*])(?=.*[0-9].*[0-9])(?=.*[a-z].*[a-z].*[a-z]).{8}$

^                         Start anchor
(?=.*[A-Z].*[A-Z])        Ensure string has two uppercase letters.
(?=.*[!@#$&*])            Ensure string has one special case letter.
(?=.*[0-9].*[0-9])        Ensure string has two digits.
(?=.*[a-z].*[a-z].*[a-z]) Ensure string has three lowercase letters.
.{8}                      Ensure string is of length 8.
$                         End anchor.

There is no duplicate ,please review the marking unless your sure it is a duplicate

kelevra88
  • 1,532
  • 3
  • 17
  • 25
  • 2
    Hi, Maria. Show your attempts.. – Avinash Raj Oct 24 '14 at 08:10
  • 2
    I don't think regexp is the right tool for this... – Maurice Perry Oct 24 '14 at 08:12
  • @Maria88 can you show an example, particularly what you mean by special character? – user224567893 Oct 24 '14 at 08:16
  • @fzzle what you found looks the same to what she's just found (and update in her question) :) – King King Oct 24 '14 at 08:25
  • 1
    Complex password rules will usually not lead to more safe passwords, important is only a minimum length. People cannot remember tons of strong passwords, and such rules can interfere with good password schemes. People can get very inventive to bypass such rules, e.g. by using weak passwords like "Password-2014". Often you end up with weaker passwords instead of stronger ones. – martinstoeckli Oct 24 '14 at 12:26
  • can i ask how this is a duplicate ?,there is no exact match to this question ,please point it out if there is ! – kelevra88 Oct 24 '14 at 13:14
  • It wouldn't be an exact duplicate. But you could figure out the answer from there... – Avinash Raj Oct 24 '14 at 13:38
  • Well while we are being technical ,the reason i asked for help was i didn't know the answer and had tried myself (as described above) duplicate tags are for duplicates of which this is not,the definition of duplicate ,describes the same. – kelevra88 Oct 24 '14 at 13:56

1 Answers1

5

try this regex will helps you

/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\W\_])[a-zA-Z0-9\W\_]{8,15}$/
Man Programmer
  • 5,300
  • 2
  • 21
  • 21
  • I suggest using `.*?` instead of `.*`, it will perform better. Also the pattern right before `$` should be just `.{8,15}` – King King Oct 24 '14 at 08:53
  • @AvinashRaj now check – Man Programmer Oct 24 '14 at 13:31
  • @AvinashRaj what is the problem with **0aA_aaaa** in string one number,Uppercase,lowerCase alphabets and **_** special character – Man Programmer Oct 24 '14 at 13:51
  • Could you please explain also a little bit what you have done there? I know only basic regex rules, like grouping, what * and ? means, choosing from [] and repeating with {min, max}, mark of the begin/end of string with ^ and $, the or condition |. I would like to understand though what you have done within each group, the begin: "?=.*"... what do these together mean? Many thanks in advance! – student0495 Mar 25 '18 at 15:17