Regex | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
+ 3


I have this code. I want to make it valid if it consist atleast one Capital letter and 1 number. It works for AB1 but not for 1BA. Any idea ?

2nd Aug 2021, 3:14 AM
sid - avatar
5 Respostas
+ 2
Your code checks for a letter followed by a digit. All you need to add is a check for a digit followed by a letter. To do that replace line 3 with the following: if'([A-Z])+([0-9])+',password) or'([0-9]+[A-Z]+', password):
2nd Aug 2021, 4:47 AM
Simon Sauter
Simon Sauter - avatar
+ 1
It looks for your variables order, you searched letter+digit
2nd Aug 2021, 4:32 AM
Dunaev Evgenii
Dunaev Evgenii - avatar
+ 1
With lookaround '(?=.*[A-Z])(?=.*[0-9])'
2nd Aug 2021, 10:56 AM
Romario - avatar
+ 1
It's late but is it what you were looking for?
13th Aug 2022, 7:18 AM
Mahad Ahmed
Mahad Ahmed - avatar
Dunaev Evgenii how to make it right if i want from both sides
2nd Aug 2021, 4:35 AM
sid - avatar