forked from namishkhanna/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckValidEmail.java
More file actions
24 lines (21 loc) · 790 Bytes
/
CheckValidEmail.java
File metadata and controls
24 lines (21 loc) · 790 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
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class CheckValidEmail {
public boolean isValidEmail(String email) {
String emailRegex = "^[\\w\\d_+&*-]+(?:\\.[\\w\\d__+&*-]+)*@(?:[\\w\\d_-]+\\.)+[a-zA-Z]{2,7}$";
Pattern p = Pattern.compile(emailRegex);
Matcher m = p.matcher(email);
return m.matches();
}
public static void main(String[] args) {
CheckValidEmail c = new CheckValidEmail();
Scanner sc = new Scanner(System.in);
System.out.println("Enter email-id to check validity:");
String email = sc.nextLine();
if (c.isValidEmail(email))
System.out.print("Valid Email ID");
else
System.out.print("Invalid Email ID");
}
}