Saturday, 30 August 2014

Email Validation in Java

Structure of the Problem Requirements 

In this problem we will learn how to validate an email address in Java Program. Java has many builtin libraries which help developers in developing . String matches function is used for this problem. In a string we define the sequence of email address and then pass this string as a argument to string matches function . Here is the source code of this problem which help you in better understanding .

Source Code

import java.util.Scanner;

public class Email{
public static void main(String[] args) {
    Scanner input = new Scanner (;
    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");
        System.out.println(" Not Validate Email ");

Output of the Program

Email Validation
Email Validation in Java Program

Share it Please

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.


Post a Comment