email validator java

Solutions on MaxInterview for email validator java by the best coders in the world

showing results for - "email validator java"
Simona
12 Oct 2020
1import java.util.regex.Matcher;
2
3import java.util.regex.Pattern;
4
5import java.util.Scanner;
6
7public class EmailValidator {
8
9	public static void main(String[] args) {
10
11		recursion();
12
13	}
14
15	static void recursion () {
16
17		Scanner scanner = new Scanner(System.in);
18
19		System.out.println("Welcome to the game of typing a correct email address!");
20		
21		System.out.println();
22		
23		System.out.println("As the game says, enter a correct email address.");
24
25		System.out.println();
26
27		String snow = scanner.nextLine();
28
29		String[] sssp = snow.split("@");
30		
31		if (sssp.length != 2) {
32			
33		System.out.println();
34			
35		System.out.println("This is not a correct email address.");	
36		
37		System.out.println();
38			
39		recursion();
40		
41		} else {
42
43			String regex = "[^a-z0-9._]";
44
45			String regex1 = "^\\.|\\.$";
46			
47			String regex2 = "\s";
48			
49			String regex3 = "^$";
50			
51			String regex7 = "\\._|_\\.";
52			
53			String regex39 = "__";
54			
55			String regex19 = "\\.\\.";
56			
57			String regex20 = "^_|_$";
58
59			Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
60
61			Pattern pattern1 = Pattern.compile(regex1, Pattern.CASE_INSENSITIVE);
62			
63			Pattern pattern2 = Pattern.compile(regex2, Pattern.CASE_INSENSITIVE);
64			
65			Pattern pattern3 = Pattern.compile(regex3, Pattern.CASE_INSENSITIVE);
66			
67			Pattern pattern11 = Pattern.compile(regex7, Pattern.CASE_INSENSITIVE);
68			
69			Pattern pattern12 = Pattern.compile(regex19, Pattern.CASE_INSENSITIVE);
70			
71			Pattern pattern13 = Pattern.compile(regex20, Pattern.CASE_INSENSITIVE);
72			
73			Pattern pattern14 = Pattern.compile(regex39, Pattern.CASE_INSENSITIVE);
74
75			Matcher matcher = pattern.matcher(sssp[0]);
76
77			Matcher matcher1 = pattern1.matcher(sssp[0]);
78			
79			Matcher matcher2 = pattern2.matcher(sssp[0]);
80			
81			Matcher matcher3 = pattern3.matcher(sssp[0]);
82			
83			Matcher matcher11 = pattern11.matcher(sssp[0]);
84			
85			Matcher matcher12 = pattern12.matcher(sssp[0]);
86			
87			Matcher matcher13 = pattern13.matcher(sssp[0]);
88			
89			Matcher matcher14 = pattern14.matcher(sssp[0]);
90
91			boolean matchFound = matcher.find();
92
93			boolean matchFound1 = matcher1.find();
94			
95			boolean matchFound2 = matcher2.find();
96			
97			boolean matchFound3 = matcher3.find();
98			
99			boolean matchFound10 = matcher11.find();
100			
101			boolean matchFound11 = matcher12.find();
102			
103			boolean matchFound12 = matcher13.find();
104			
105			boolean matchFound13 = matcher14.find();
106			
107			String hello = sssp[1];
108			
109			String[] whoop = hello.split("\\.", 2);
110			
111			if (whoop.length != 2) {
112				
113			System.out.println();
114
115			System.out.println("This is not a correct email address.");	
116
117			System.out.println();	
118				
119			recursion();
120			
121			} else {
122				
123				String regex4 = "[^a-z]";
124				
125				String regex5 = "^$";
126				
127				String regex6 = "\s";
128				
129				Pattern pattern4 = Pattern.compile(regex4, Pattern.CASE_INSENSITIVE);
130
131				Pattern pattern5 = Pattern.compile(regex5, Pattern.CASE_INSENSITIVE);
132				
133				Pattern pattern6 = Pattern.compile(regex6, Pattern.CASE_INSENSITIVE);
134				
135				Matcher matcher4 = pattern4.matcher(whoop[0]);
136
137				Matcher matcher5 = pattern5.matcher(whoop[0]);
138				
139				Matcher matcher6 = pattern6.matcher(whoop[0]);
140				
141				boolean matchFound4 = matcher4.find();
142
143				boolean matchFound5 = matcher5.find();
144				
145				boolean matchFound6 = matcher6.find();
146				
147				Pattern pattern7 = Pattern.compile(regex4, Pattern.CASE_INSENSITIVE);
148
149				Pattern pattern8 = Pattern.compile(regex5, Pattern.CASE_INSENSITIVE);
150				
151				Pattern pattern9 = Pattern.compile(regex6, Pattern.CASE_INSENSITIVE);
152				
153				Matcher matcher7 = pattern7.matcher(whoop[1]);
154
155				Matcher matcher8 = pattern8.matcher(whoop[1]);
156				
157				Matcher matcher9 = pattern9.matcher(whoop[1]);
158				
159				boolean matchFound7 = matcher7.find();
160
161				boolean matchFound8 = matcher8.find();
162				
163				boolean matchFound9 = matcher9.find();
164				
165				System.out.println();
166
167				if(matchFound || matchFound1 || matchFound2 || matchFound3 || matchFound4 || matchFound5 || matchFound6 || matchFound7 || matchFound8 || matchFound9 || matchFound10 || matchFound11 || matchFound12 || matchFound13) {
168
169					System.out.println("This is not a correct email address.");
170
171					System.out.println();
172
173					recursion();
174
175				} else {
176
177					System.out.println("This is a correct email address.");
178
179					System.out.println();
180
181					System.out.println("Do you still want to play? (say yes to play) ");
182
183					System.out.println();
184
185					Scanner scanner1 = new Scanner(System.in);
186
187					String snow1 = scanner1.nextLine();
188
189					if (snow1.equalsIgnoreCase("yes")) {
190
191						System.out.println();
192
193						recursion();
194
195					} else {
196
197						System.out.println();  
198
199						System.out.println("Okay, then.");  
200						
201						scanner.close();
202						
203						scanner1.close();
204						
205					}
206
207				}	
208				
209			}
210			
211		}
212
213	}
214	
215}
216
queries leading to this page
email validation with javahow to use matcher and matcher in email validation javajava validate emailvalidate email javavalide email in javajava check if valid emailhow to add email validation in javahow to validate an email in javacheck if email id is valid in javahow to implement email validation inside java codejava check email is validcheck if text is an email javaemail format java checkhow to use matcher and matches in email validadtion javavalidating email address in javajava program to find whether email is validjava validate that email is samejava code to check if email address is validhow to check if an email is valid javavalidate email in java using regechow to check email validation in javahow check the validation of email in javapattern email validation javahow to implement email validator inside java codejava valid email inputhow to validate email java java email validationemail string validation javachecking valid email javajava best email validationemail validation for javaemail address validate javajava validate email regexjava code for email validationvalidar email javaemail validation javavalidate email built in method javavalidate email in javais email valid javaemail java validationhow to create valid email validation in javahow to validate email address in javaemail id validation in javaemail validator java email validation in javaemail validation and exception in javajava check if email is validhow to check valid email address in javavalid email javaemail validate on server java 5ccheck valid email id in javainput email validation javavalidate email in 22java 22java check emailvalidation email in javavalidation in java for emailvalidate email id in java with 40 2c validating email in javaemail validator java 7validate email id in javaemail validator java7how to add email validations in javajava check email formatcheck email is valid or not in javahow to validate email in javaemail validator java