JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PasswordValidator
{
public static void main(String[] args) {
String pswd1 = "NonValid";
String pswd2 = "inv";
String pswd3 = "qwert1w3";
//pattern for checking that only
//letters and digit's in the String and;
//it's number of characters is 8 or more
String pattern1 = "[a-zA-Z]{8,}";
//pattern for checking that at least 2 digit's
//are present in the string
String pattern2 ="(.*\\d.*){2,}";
//test passwords
printValidation(pswd1, pattern1, pattern2);
printValidation(pswd2, pattern1, pattern2);
printValidation(pswd3, pattern1, pattern2);
}
/**
* Is there in the string match the pattern;
* @param pswd string for checking;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run