1 |
51979
|
sofia.balt
|
package eu.dnetlib.openaire.user.utils;
|
2 |
|
|
|
3 |
|
|
import org.apache.log4j.Logger;
|
4 |
|
|
|
5 |
|
|
/**
|
6 |
|
|
* Created by sofia on 20/4/2018.
|
7 |
|
|
*/
|
8 |
|
|
public class InputValidator {
|
9 |
|
|
|
10 |
|
|
private static Logger logger = Logger.getLogger(InputValidator.class);
|
11 |
|
|
|
12 |
|
|
/*
|
13 |
|
|
^ # start-of-string
|
14 |
|
|
(?=.*[0-9]) # a digit must occur at least once
|
15 |
|
|
(?=.*[a-z]) # a lower case letter must occur at least once
|
16 |
|
|
(?=.*[A-Z]) # an upper case letter must occur at least once
|
17 |
|
|
(?=.*[@#$%^&+=]) # a special character must occur at least once. This has been removed.
|
18 |
|
|
# Please add if special character is needed.
|
19 |
|
|
(?=\S+$) # no whitespace allowed in the entire string
|
20 |
|
|
.{6,} # anything, at least six places though
|
21 |
|
|
$ # end-of-string
|
22 |
|
|
*/
|
23 |
|
|
|
24 |
|
|
public static String validPassword = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=\\S+$).{6,}$";
|
25 |
|
|
|
26 |
|
|
/*
|
27 |
|
|
^[a-zA-Z0-9] # starts with character or digit
|
28 |
|
|
^[a-zA-Z0-9\\.\\_\\-] # contains only characters, numbers, underscores, hyphens, periods
|
29 |
|
|
{4,150} # anything, at least eight places though
|
30 |
|
|
$ # end-of-string
|
31 |
|
|
*/
|
32 |
|
|
public static String validUsername = "^[a-zA-Z0-9][a-zA-Z0-9\\.\\_\\-]{4,150}";
|
33 |
|
|
|
34 |
|
|
/*
|
35 |
|
|
^[a-zA-Z0-9] # starts with character or digit
|
36 |
|
|
*/
|
37 |
|
|
public static String startsWith = "^[a-zA-Z0-9].*";
|
38 |
|
|
|
39 |
|
|
/*
|
40 |
|
|
"^[a-zA-Z0-9\\.\\_\\-]" #contains only characters, numbers, underscores, hyphens, periods
|
41 |
|
|
*/
|
42 |
|
|
public static String allowedChars = "^[a-zA-Z0-9\\.\\_\\-]";
|
43 |
|
|
|
44 |
|
|
public static boolean isFilled(String input) {
|
45 |
|
|
return (input != null && !input.isEmpty());
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
public static boolean isValidPassword(String password) {
|
49 |
|
|
return password.matches(validPassword);
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
public static boolean isValidUsername(String username) {
|
53 |
|
|
return username.matches(validUsername);
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
public static boolean startsWithLetterOrDigit(String username) {
|
57 |
|
|
return username.matches(startsWith);
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
public static boolean containsOnlyAllowedChars(String username) {
|
61 |
|
|
return username.matches(allowedChars);
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
public static boolean containsLessCharsThan(int count, String input) {
|
65 |
|
|
return (input.length() < count);
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
public static boolean containsMoreCharsThan(int count, String input) {
|
69 |
|
|
return (input.length() > count);
|
70 |
|
|
}
|
71 |
|
|
}
|