Java Regular Expression Email Validation

Java Regular expression program to represent all valid mail ids:

[a-z][A-Z][0-9][a-z][A-Z][0-9_.]* @ [a-zA-Z0-9] + ([.][a-zA-Z]+)+

Only gmail id is:

[a-zA-Z0-9] [a-zA-Z0-9_.]* @ gmail[.]com


Java Regular expression program to check whether a given mail id is valid or invalid mail id.

import java.util.regex.*;
class RegexDemo7
public static void main(String[] args)
Pattern p=Pattern.compile("[a-zA-Z0-9][a-zA-Z0-9_.]*@[a-zA-Z0-9]+([.][a-zA-Z]+)+");
Matcher m=p.matcher(args[0]);
if(m.find() &&[0]))
System.out.println("valid mail id");
System.out.println("invalid mail id");

1st run : java RegexDemo7
valid mail id
2nd run : java RegexDemo7 trilochan4u
invalid mail id

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Data Science with Python Training | Projects

SILAN Technology, BBSR
Call to: 0674-2361252