java - How to check if there is at least: two letters, one number and one special character? -


how check if there @ least: 2 letters, 1 number , 1 special character in java? here code dont know if i'm in right direction.

public static boolean validarcodigo(string codigo){     //return pattern.compile("[abc]").matcher("ba").find();     boolean containsatleasttwoletters = pattern.compile("[0-9]").matcher(codigo).find();     boolean tienealmenosdosletras = pattern.compile("('/[a-za-   z]/')").matcher(codigo).find();     boolean containsatleastonespecialchar; = pattern.compile ("'/[^a-za-z\\d]/'").matcher(codigo).find();             return containsatleastonedigit && containsatleasttwoletters && containsatleastonespecialchar; 

your regex seems bit off you've done job. 1 main thing you're checking one number , letter. solve this, try following regexes:

boolean containsatleasttwoletters = pattern.compile("[0-9].*[0-9]").matcher(codigo).find(); boolean tienealmenosdosletras = pattern.compile("[a-za-z].*[a-za-z").matcher(codigo).find(); boolean containsatleastonespecialchar = pattern.compile ("[^a-za-z\\d]").matcher(codigo).find();    

i took freedom reformat variables java standard practice (likethis instead of likethis).


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -