Here goes the 3 functions :
public class abc{
public static void main(String[] args){
inputEmail();
}
public boolean checkEmailvalidity(String emailaddress){
String email_regex = "[A-Z]+[a-zA-Z_]+@\b([a-zA-Z]+.){2}\b?.[a-zA-Z]+";
boolean b = testString.matches(email_regex);
return b;
}
public void inputEmail(){
System.out.println("Please enter your email address ex:xyz@gmail.com");
String emailaddress=name.nextLine();
boolean a = checkEmailvalidity(emailaddress);
if(a){
System.out.println("Valid email");
} else {
System.out.println("InValid email");
inputEmail();
}
}
}
here is with your updated answer :
package smsmain;
import java.util.Scanner;
public class CStudentinfo {
public static void createstudent() {
Scanner name = new Scanner(System.in);
System.out.println("Please enter your first name:");
while(!name.hasNext("[a-zA-Z]+")){
System.out.println("Please re-enter your name, use alphabets)
System.out.println("Please enter your first name:");
name.nextLine();
}
String firstname=name.nextLine();
System.out.println("Your firstname is " + firstname);
inputEmail();