|
8 | 8 | */ |
9 | 9 | public class Regex { |
10 | 10 |
|
11 | | - public static final String REGEX_NUMBER = "^-?[0-9]\\d*(\\.\\d+)?$"; |
12 | | - public static final String REGEX_ALPHA_NUMERIC = "^[a-zA-Z0-9]*$"; |
13 | | - public static final String REGEX_EMAIL = |
14 | | - "^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))[^_@!*]*?$"; |
| 11 | + public static final String REGEX_NUMBER = "^-?[0-9]\\d*(\\.\\d+)?$"; |
| 12 | + public static final String REGEX_ALPHA_NUMERIC = "^[a-zA-Z0-9]*$"; |
| 13 | + public static final String REGEX_EMAIL = |
| 14 | + "^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))[^_@!*]*?$"; |
15 | 15 |
|
16 | | - public static final Pattern EMAIL_PATTERN = Pattern.compile(REGEX_EMAIL); |
| 16 | + public static final Pattern EMAIL_PATTERN = Pattern.compile(REGEX_EMAIL); |
17 | 17 |
|
18 | | - /** |
19 | | - * Returns {@code true} if the provided String is valid number otherwise |
20 | | - * returns {@code false}. |
21 | | - * |
22 | | - * @param value a String to be checked against number regular expression |
23 | | - * @return Returns {@code true} if the provided String is valid number otherwise |
24 | | - * returns {@code false}. |
25 | | - */ |
26 | | - public static boolean isNumber(String value){ |
27 | | - return Objects.nonNull(value) && value.matches(Regex.REGEX_NUMBER); |
28 | | - } |
| 18 | + /** |
| 19 | + * Returns {@code true} if the provided String is valid number otherwise |
| 20 | + * returns {@code false}. |
| 21 | + * |
| 22 | + * @param value a String to be checked against number regular expression |
| 23 | + * @return Returns {@code true} if the provided String is valid number otherwise |
| 24 | + * returns {@code false}. |
| 25 | + */ |
| 26 | + public static boolean isNumber(String value) { |
| 27 | + return Objects.nonNull(value) && value.matches(Regex.REGEX_NUMBER); |
| 28 | + } |
29 | 29 |
|
30 | | - /** |
31 | | - * Returns {@code true} if the provided String is valid alpha numeric otherwise |
32 | | - * returns {@code false}. |
33 | | - * |
34 | | - * @param value a String to be checked against alpha numeric regular expression |
35 | | - * @return Returns {@code true} if the provided String is valid alpha numeric otherwise |
36 | | - * returns {@code false}. |
37 | | - */ |
38 | | - public static boolean isAlphaNumeric(String value) { |
39 | | - return Objects.nonNull(value) && value.matches(Regex.REGEX_ALPHA_NUMERIC); |
40 | | - } |
| 30 | + /** |
| 31 | + * Returns {@code true} if the provided String is valid alpha numeric otherwise |
| 32 | + * returns {@code false}. |
| 33 | + * |
| 34 | + * @param value a String to be checked against alpha numeric regular expression |
| 35 | + * @return Returns {@code true} if the provided String is valid alpha numeric otherwise |
| 36 | + * returns {@code false}. |
| 37 | + */ |
| 38 | + public static boolean isAlphaNumeric(String value) { |
| 39 | + return Objects.nonNull(value) && value.matches(Regex.REGEX_ALPHA_NUMERIC); |
| 40 | + } |
41 | 41 |
|
42 | | - /** |
43 | | - * Returns {@code true} if the provided String is valid email otherwise |
44 | | - * returns {@code false}. |
45 | | - * |
46 | | - * @param value a String to be checked against email regular expression |
47 | | - * @return Returns {@code true} if the provided String is valid email otherwise |
48 | | - * returns {@code false}. |
49 | | - */ |
50 | | - public static boolean isValidEmail(String value) { |
51 | | - return Objects.nonNull(value) && Regex.EMAIL_PATTERN.matcher(value).matches(); |
52 | | - } |
| 42 | + /** |
| 43 | + * Returns {@code true} if the provided String is valid email otherwise |
| 44 | + * returns {@code false}. |
| 45 | + * |
| 46 | + * @param value a String to be checked against email regular expression |
| 47 | + * @return Returns {@code true} if the provided String is valid email otherwise |
| 48 | + * returns {@code false}. |
| 49 | + */ |
| 50 | + public static boolean isValidEmail(String value) { |
| 51 | + return Objects.nonNull(value) && Regex.EMAIL_PATTERN.matcher(value).matches(); |
| 52 | + } |
53 | 53 | } |
0 commit comments