What would be a simple regex for password verification during registration?

What I want to do is simply check, when the user logs in, whether the entered password is entered at least 6 characters and there is no place in it. This is pretty much the case. What would be a regular expression that I could use in the template classes of Java templates for this purpose?

Thanks for helping the guys.

+3
source share
4 answers

Why do you need regex?

String str = "my pass";

if (str.length() < 6 || str.contains(" ")){

fail();
}
+2
source

Why do you want to use regex?

public boolean isPasswordValid( String password )
{
    return ((password.length() >= 6) && (!password.contains(" "));
}
+3
source
^[^ ]{6,}$

^... $ [^] 6 {6,}

+3

The matrix pattern is a bit overhead; you can use the following:

String password = ...;
final int PASS_MIN_LEN = 6;
if (password.length >= PASS_MIN_LEN && password.indexOf(' ') < 0) {
 // proceed
} else {
 // error 
}
+2
source

Source: https://habr.com/ru/post/1777763/


All Articles