java string length validation regex

Solutions on MaxInterview for java string length validation regex by the best coders in the world

showing results for - "java string length validation regex"
Erik
22 Jan 2021
1//Password validation example
2public static Boolean validPassword(String password) throws IllegalArgumentException {
3   if (!password.matches("\\w{6,}"))/*Or '(password.matches("\\w{6,}") == false)'*/ {
4      throw new IllegalArgumentException("Password must be at least 6 characters long.");
5   
6   //'("\\w{int}")' => Must be int characters long.
7   //'("\\w{int,}")' => Must be AT LEAST int characters long and can be longer.
8   //'("\\w{int1,int2}")' => Must be BETWEEN int1 AND int2 characters long.
9   
10   }
11   return true;
12}