-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmailIsValidRequirement.java
54 lines (40 loc) · 1.7 KB
/
EmailIsValidRequirement.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.jcp.automation.common.requirements;
import com.jcp.automation.common.ErrorCodes;
/**
* @author ykrasnopolskiy
* @since 3/19/17.
*/
public class EmailIsValidRequirement extends AbstractRequirement {
private String validEmailRegex = "[_A-Za-z0-9\\-+]+(\\.[_A-Za-z0-9\\-]+)*@[A-Za-z0-9\\-]+([\\-_.][A-Za-z0-9]+)*(\\.[A-Za-z]{2,})";
private String pciCompliantEmailRegex = "[a-zA-Z0-9@.\\-/+=_ ]*";
public String getPciCompliantEmailRegex() {
return pciCompliantEmailRegex;
}
public void setPciCompliantEmailRegex(String pciCompliantEmailRegex) {
this.pciCompliantEmailRegex = pciCompliantEmailRegex;
}
public String getValidEmailRegex() {
return validEmailRegex;
}
public void setValidEmailRegex(String validEmailRegex) {
this.validEmailRegex = validEmailRegex;
}
/**
* The constructor is planned to be used only to instantiate Requirement inside Requirements enum
*/
EmailIsValidRequirement(ErrorCodes associatedErrorIfNotMeetRequiement){
setErrorCode(associatedErrorIfNotMeetRequiement);
}
@Override
public boolean meets(Object objectToCheck) {
String stringToCheck = objectToCheck != null ? objectToCheck.toString() : null;
return org.apache.commons.lang.StringUtils.isEmpty(stringToCheck)
|| (validateEmailPCICompliant(stringToCheck) && validateEmailAddress(stringToCheck));
}
private boolean validateEmailAddress(String value) {
return value.matches(validEmailRegex);
}
private boolean validateEmailPCICompliant(String value){
return value.matches(pciCompliantEmailRegex);
}
}