Created with <3 with dartpad.dev.
Created
October 31, 2023 02:25
-
-
Save leonus96/3e888c70784382bca8b452860014b442 to your computer and use it in GitHub Desktop.
3. contraseña_v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///Ejercicio 3 - Validación de Contraseña: | |
/// Escribe una función que verifique si una | |
/// contraseña es válida. La contraseña | |
/// debe tener al menos 8 caracteres y un número. | |
void main() { | |
final password = 'dsdsdsdsdsdsd'; | |
if(validatePassword(password)) { | |
print('Contraseña válida'); | |
} else { | |
print('Contraseña inválida'); | |
} | |
} | |
bool validatePassword(String password) { | |
final size = password.length; | |
if (size < 8) { | |
return false; | |
} | |
for (int i = 0; i < password.length; i++) { | |
for(int j = 1; j < 10; j++) { | |
if(password[i] == j.toString()) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
/// contraseña => '12345678'; | |
/// '1' '2' '3' '4' '5' '6' '7' '8' | |
// v1 : == '1' || == '2' ... | |
// v2 : == 1.toString() ==> '1' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment