Email Validation in Java

Java has many builtin libraries that help developers in developing amazing apps. String matches function is used to validate the email address. In a string we define the sequence of email address and then pass this string as a argument to string matches function.

Source Code


import java.util.Scanner;

public class Email{
public static void main(String[] args) {
   
    Scanner input = new Scanner (System.in);
    String email_validation = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$";
    String email = "";
    System.out.println(" Enter Email Address ");
    email= input.nextLine();
    if (email.matches(email_validation))
    {
        System.out.println(" Validate Email");
    }
    else
    {
        System.out.println(" Not Validate Email ");
    }
    
   }   
     }

Output of the Program

Email Validation

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment