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() && m.group().equals(args[0]))
{
System.out.println("valid mail id");
}
else
{
System.out.println("invalid mail id");
}
}
}

Output:
1st run : java RegexDemo7 trilochan4u@gmail.com
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
Call to: 9439202111  |  9658317757  |  0674-2361252

Comment