sticky
Password Strength Expression

    Pergunta

  • It's been a while since I've had to use regular expressions.

    Can someone explain this to me in layman's terms?

    ^(?=.{8,30})(?=.*[^A-Za-z])(?=.*[A-Z])(?=.*[a-z]).*
    terça-feira, 9 de fevereiro de 2010 19:43

Respostas

  • These are all assertions...

    ^ = starting from the beginning of the string...
    (?=.{8,30}) = there is a string that is at least 8 characters long... (the upper bound of 30 cannot work this way)
    (?=.*[^A-Za-z]) = somewhere in the string, there is at least one non-alphabetic character...
    (?=.*[A-Z]) = somewhere in the string, there is at least one uppercase character...
    (?=.*[a-z]) = somewhere in the string, there is at least one lowercase character....

    .* match anyting, provided that all the above conditions are met.

    HTH
    --mc
    • Marcado como Resposta LarryEis terça-feira, 9 de fevereiro de 2010 20:16
    terça-feira, 9 de fevereiro de 2010 20:14

Todas as Respostas

  • These are all assertions...

    ^ = starting from the beginning of the string...
    (?=.{8,30}) = there is a string that is at least 8 characters long... (the upper bound of 30 cannot work this way)
    (?=.*[^A-Za-z]) = somewhere in the string, there is at least one non-alphabetic character...
    (?=.*[A-Z]) = somewhere in the string, there is at least one uppercase character...
    (?=.*[a-z]) = somewhere in the string, there is at least one lowercase character....

    .* match anyting, provided that all the above conditions are met.

    HTH
    --mc
    • Marcado como Resposta LarryEis terça-feira, 9 de fevereiro de 2010 20:16
    terça-feira, 9 de fevereiro de 2010 20:14
  • Thanks.
    terça-feira, 9 de fevereiro de 2010 20:17

  • (?=.{8,30}) = there is a string that is at least 8 characters long... (the upper bound of 30 cannot work this way)

    Mario has a point...the above fails. To enforce the thirty character limit change the pattern to this:

    ^(?!.{31})(?=.{8})(?=.*[^A-Za-z])(?=.*[A-Z])(?=.*[a-z]).*$


    (?!.{31})  - Match invalidator, if it finds 31 characters it invalidates the match. Nothing returned
    $ - END of line

     

    To add to Mario's, correct, statement

    .* Match anything, zero or more times.

     

     


    William Wegerson (www.OmegaCoder.Com )
    • Sugerido como Resposta _Jazz terça-feira, 22 de fevereiro de 2011 19:08
    terça-feira, 9 de fevereiro de 2010 21:26
  • This pattern surely limits 30 chars and also accepts one or more numeral, small case and upper case alphabets.
    Regards, Rule the Codes and Code New Rules
    terça-feira, 22 de fevereiro de 2011 19:10
  • great stub !!
    Vedigoundan Gurunathan
    sexta-feira, 4 de março de 2011 04:29
  • Very good !
    quarta-feira, 13 de abril de 2011 13:39
  • Hi LarryEis,

    Use the below expression,

    ^(?!.{31})(?=.{8})(?=.*[^A-Za-z])(?=.*[A-Z])(?=.*[a-z]).*$


    ^  = starting from the beginning of the string
    (?=.{8,31}) = there is a string that is at least 8 characters long... (the upper bound of 31)
    (?=.*[^A-Za-z]) = somewhere in the string, there is at least one non-alphabetic character
    (?=.*[A-Z]) = somewhere in the string, there is at least one uppercase character
    (?=.*[a-z]) = somewhere in the string, there is at least one lowercase character

    Thanks

    Roozan Bharucha

    MCT, MCPD Windows Frmwk 4.0

    • Sugerido como Resposta Rex Honour segunda-feira, 25 de abril de 2011 09:34
    segunda-feira, 25 de abril de 2011 07:52
  • This regex can also be helpful:

    {8,15}$)(?=.*\d)((?=.*\W+)|(?=.*[A-Z]))(?![.\n]).*$

     

    This is according to the standards which asks for minimum 8 to maximum 15 characters

    One mandatory UpperCase Alphabet,

    One mandatory LowerCase Alphabet,

    One mandatory Number.

    sexta-feira, 29 de abril de 2011 10:13
  • Yes , I agree with this ?= is the condition if the case is this then whats the result

    \ is the escape case

    [A-Z] any character between A -Z

    * any case i.e small or capital letters

    8-15 strength of the letter

    segunda-feira, 23 de maio de 2011 07:21
  • Assert a string is 8 or more characters:
    (?=.{8,})

    Assert a string contains at least 1 lowercase letter (zero or more characters followed by a lowercase character):
    (?=.*[a-z])

    Assert a string contains at least 1 uppercase letter (zero or more characters followed by an uppercase character):
    (?=.*[A-Z])

    Assert a string contains at least 1 digit:
    (?=.*[\d])

    Assert a string contains at least 1 special character:
    (?=.*[\W])

    Assert a string contains at least 1 special character or a digit:
    (?=.*[\d\W])

    • Sugerido como Resposta Mustee01 segunda-feira, 4 de julho de 2011 20:08
    • Não Sugerido como Resposta Mustee01 segunda-feira, 4 de julho de 2011 20:09
    sábado, 18 de junho de 2011 17:34
  • Regular expressions are one of those things where you have to keep in practise as it could become quite complicated.. But if you don't use it for a while and suddenly jump into it again, it all comes back..
    terça-feira, 7 de fevereiro de 2012 09:00
  • Please visit following link:

    http://www.zorched.net/2009/05/08/password-strength-validation-with-regular-expressions/

    segunda-feira, 13 de fevereiro de 2012 05:36
  • I need one for

    Minimum of 8 (eight) characters and at least 1 non-alphanumeric characters.

    Is it right?

    ^(?=.{8,})(?=.*[^A-Za-z])*

    terça-feira, 14 de fevereiro de 2012 17:10
  • Refer Following urls

    http://www.zorched.net/2009/05/08/password-strength-validation-with-regular-expressions/

    http://www.techpint.com/programming/regular-expression-check-password-strength


    Gehan Fernando Snr. Engineer Technology. AKLO Information Technologies (Pvt) Ltd. #58, 42nd Lane, 5th Floor, Wellawatta, Colombo 06, Sri Lanka. Phone: +94 117 520000 | Mobile: +94 772 269625

    • Sugerido como Resposta ardmore quarta-feira, 23 de maio de 2012 12:46
    quarta-feira, 23 de maio de 2012 10:00