forked from cs-dept-ibbul/java2019
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabTwo_emailBreak.java
More file actions
30 lines (26 loc) · 1.03 KB
/
Copy pathlabTwo_emailBreak.java
File metadata and controls
30 lines (26 loc) · 1.03 KB
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
package practicalClass;
import java.util.Scanner;
//Program to break inputed email into username and domain name
//U16/FNS/CSC/2061
public class labTwo_emailBreak {
public static void main(String[] args) {
Scanner userInput=new Scanner(System.in);
String testString,emailAddress;
boolean check;
do {
System.out.println("Please enter your email e.g: example@mail.com");
emailAddress=userInput.nextLine();
//String email_regex="[A-Z]+[a-zA-Z_]+@\b([a-zA-Z]+.) {2}\b?.[a-zA-Z]+";
String email_regex="^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"+"[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
testString=emailAddress;
check=testString.matches(email_regex);
if(!check) {
System.out.println("The email : \""+emailAddress+ "\" is Invalid\n");
//return;
}
}while(!check);
String[] parts= emailAddress.split("@");
System.out.println("\nFor the email address: "+emailAddress);
System.out.println("The user name is : "+parts[0]+"\nThe domain name is : "+parts[1]);
}
}