Email validator in java

You can use the below validator class for email address in your java projects,

/*
Email Validator
*/
package com.tms.utility;

import java.util.regex.Pattern;

/**
*
* @author aarnav
*/
public class EmailValidator {

private static final String EMAIL_PATTERN
= "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

public EmailValidator() {

}

/**
* Validate hex with regular expression
*
* @param email for validation
* @return true valid email, false invalid email
*/
public static boolean validate(String email) {
Pattern pattern = Pattern.compile(EMAIL_PATTERN);
return pattern.matcher(email).matches();

}

}

4 thoughts on “Email validator in java

  1. Rajesh Nandan says:

    I ‘ve been searching for it, you saved me. Thanks!

    1. Ourhints says:

      Welcome !

  2. Abhishek says:

    tihs is what I was looking for.

  3. Abhishek says:

    Great site and ocntent

Leave a Reply

Your email address will not be published. Required fields are marked *