<input type="password" name="password" pattern="^[AZ][az]{4,}[0-9]{4,}$"> 

I can't figure out how to change a regular expression to get the condition for at least one uppercase letter, not necessarily the FIRST .

  • Should numbers and lower case letters also be present? With a random order, or in the one that is listed now in a regular expression? - cheops
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

3 answers 3

Password field: Minimum 8 characters, one digit, one uppercase letter and one lowercase

 ^(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[AZ])(?=.*[az]).*$ 

Took from here .

  • Lying in the description of a regular expression. - Visman

Sorry for the incorrectly formulated question. The task was this: the password should consist of at least 8 characters, 4 of which are digits, 4 letters (at least one upper and at least one lower case). It turned out so. Thanks for the tips!

 ^(?=.*[az])(?=.*[AZ]).{4,}(?=.*\d).{4,}$ 
 "^.*[AZ]+.*$" 

Means "Start of line, any character 0 or more times, capital letter 1 or more times, any character 0 or more times, end of line".

An expression that exactly matches the task:

condition of at least one uppercase letter

UPD. As Numminorich correctly observed,

in general, it would be possible to reduce to "[AZ]+" , well, if necessary, add Russian letters

  • in general, it would be possible to reduce to "[AZ]+" , well, if necessary, add Russian letters - NumminorihSF