The regular expression, "String regex = "[0-9a-z]+@[0-9a-z]+.+[0-9a-z]";"
, is used for testing a email validation. Basically, im trying to make it so that an email will only match this patter if the email begins with a string of alphanumeric chars, followed by 1 @ symbol, followed by another string of alphanumeric chars, followed by 1 ., and then finally a string of alphanumeric chars. Whats failing is that when i enter an email without a string of alphanumerics after the last ., the program will still match with the regex string. How do i make it so that there MUST be another string of alphanumerics after the .? The whole code is:
import java.util.Scanner;
import java.util.regex.*;
public class Regex
{
public static void main (String[]args){
Scanner input = new Scanner(System.in);
System.out.println("Please enter your Email");
String mail = input.nextLine();
String regex = "[0-9a-z]+@[0-9a-z]+.+[0-9a-z]";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(mail);
if(m.find()) {
System.out.println("VALID");
} else {
System.out.println("INVALD");
}
}
}