java - Translating a regex into a more basic code -


how can write below code without using regex?

public static boolean validatecode(string code){     boolean hasatleastonenumber = pattern.compile("[0-9].*[0-9]")                                          .matcher(code).find();      boolean hasatleasttwoletters = pattern.compile("[a-za-z].*[a-za-z]")                                           .matcher(code).find();      boolean hasatleastonehyphen = pattern.compile("-")                                          .matcher(code).find(); } 

how

public static boolean validatecode2(string code) {     int numbers = 0, letters = 0, hyphens = 0;     (char c : code.tochararray()) {         if (character.isdigit(c)) numbers++;         if (character.isalphabetic(c)) letters++;         if (c=='-') hyphens++;     }      return numbers>=2 && letters>=2 && hyphens>=1; } 

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 -