forked from gaurav03kr/hello-hacktoberfest-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emailvalidation.java
29 lines (23 loc) · 921 Bytes
/
emailvalidation.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
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.validator.routines.EmailValidator;
public class EmailValidation {
public static boolean isValidEmail(String email) {
// create the EmailValidator instance
EmailValidator validator = EmailValidator.getInstance();
// check for valid email addresses using isValid method
return validator.isValid(email);
}
public static void main(String[] args) {
List<String> emails = new ArrayList<String>();
// valid email addresses
emails.add("[email protected]");
emails.add("[email protected]");
//invalid email addresses
emails.add("email.example.com");
emails.add("[email protected]");
for (String value : emails) {
System.out.println("The Email address " + value + " is " + (isValidEmail(value) ? "valid" : "invalid"));
}
}
}