0
static let password = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$"

I have this regex to validate password

  • at least one character
  • at least one Capital character
  • at least one number
  • length more than 8

I need to update it to

  • prevent any repeated sequence of characters or numbers to prevent "111111" or "aaaaaaa" for example
  • to prevent starting and ending with space character

how to update my regex to match those requirements ?

Bassant Ashraf
  • 1,531
  • 2
  • 16
  • 23
  • Try `let password = "^(?=.{8})(?!.*([a-zA-Z\\d])\\1)(?=\\D*\\d)(?=[^a-z]*[a-z])(?=[^A-Z]*[A-Z])\\S.*\\S$"` – Wiktor Stribiżew Oct 18 '18 at 12:05
  • related: https://stackoverflow.com/questions/19928791/regex-for-password-repetative-characters https://stackoverflow.com/questions/17768298/regular-expression-to-match-string-not-starting-with-or-ending-with-spaces – Sebastian Proske Oct 18 '18 at 12:06
  • You know, to prevent spaces in the beginning and ending, I would evaluate putting a listener on the password field and, whenever it changes (char added), I would call a trim function. It could be an option to "reject the input" instead of refusing a whole password. Not sure it would be the best option though... – Leonardo Alves Machado Oct 18 '18 at 12:09
  • https://stackoverflow.com/a/31954533/2303865 – Leo Dabus Oct 18 '18 at 13:13

0 Answers0