-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemailvald.java
More file actions
37 lines (26 loc) · 846 Bytes
/
emailvald.java
File metadata and controls
37 lines (26 loc) · 846 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
30
31
32
33
34
35
36
37
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.IOException;
import java.util.ArrayList;
public class validEmail {
public static boolean isValid(String email) {
String regex = "^[a-zA-Z0-9_+&*-]+(?:\\." + "[a-zA-Z0-9_+&*-]+)*@" + "(?:[a-zA-Z0-9-]+\\.)+[a-z" +
"A-Z]{2,7}$";
Pattern pat = Pattern.compile(regex);
if(email == null)
return false;
else
return pat.matcher(email).matches();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner crn = new Scanner(System.in);
home System.out.println("Enter your email please!");
String str = crn.nextLine();
if(isValid(str))
System.out.println(str + " - Yes");
else
System.out.println(str + " - No");
}
}