-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathEmployeeEmail.java
More file actions
29 lines (25 loc) · 932 Bytes
/
EmployeeEmail.java
File metadata and controls
29 lines (25 loc) · 932 Bytes
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
package guru.springframework.unittest.asserts;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.*;
public class EmployeeEmail {
//0312
Map<String, String> hashMap = new HashMap<String, String>();
public void addEmployeeEmailId(String key, String value){
if(isValidEmailId(value)) {
hashMap.put(key, value);
}
}
public String getEmployeeEmailId(Object key){
if (!(key instanceof String)) {
throw new IllegalArgumentException("Object not type of String");
}
return hashMap.get(key);
}
public boolean isValidEmailId(String email){
String regex = "^[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,}))$";
Pattern pattern = Pattern.compile(regex);
Matcher m = pattern.matcher(email);
return m.matches();
}
}