devxlogo

Email Address Validation Using a Regular Expression

Email Address Validation Using a Regular Expression

The following code demonstrates how to validate email using regular expression:

import java.util.regex.*;class regexSample {   public static void main(String args[])    {      //Input the string for validation      String email = "[email protected]";      //Set the email pattern string      Pattern p = Pattern.compile(".+@.+\.[a-z]+");      //Match the given string with the pattern      Matcher m = p.matcher(email);      //check whether match is found       boolean matchFound = m.matches();      if (matchFound)        System.out.println("Valid Email Id.");      else        System.out.println("Invalid Email Id.");   }}

Editor’s Note: This tip can incorrectly validate some malformed email addresses. You can find an updated version here.

See also  Essential Measures for Safeguarding Your Digital Data
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist