Showing posts with label How to Validate email address in java. Show all posts
Showing posts with label How to Validate email address in java. Show all posts

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 (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
Email Validation in Java Program