Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to validate email java

import java.util.regex.Pattern;

public class EmailValidation {
  	// Creating The actual Method
    public String validateEmail(String email) {
        if (email == null || email.isEmpty()) {
            return "Nothing to be validated";
        }
        String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:." +"[a-zA-Z0-9_+&*-]+)*@" + "(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,7}$";
        Pattern pattern = Pattern.compile(emailRegex);
        if (pattern.matcher(email).matches()) {
            return "It's valid";
        } 
        return "Email not valid";
    }
  	// Everything below this point is for testing that it works
    public static void main(String[] args) {
        EmailValidation emailValidator = new EmailValidation();
        String email1 = "ola.Nordmann@online.no";
        String email2 = "foobar";

        System.out.println("Email1: " + email1 + " " + emailValidator.validateEmail(email1));
        System.out.println("Email2: " + email2 + " " + emailValidator.validateEmail(email2));
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to get an array as input in java 
Java :: java get mouse coordinates 
Java :: transparent dialog in android 
Java :: java file dialog 
Java :: love2d set screen size 
Java :: android studio centering textview in relativelayout 
Java :: declaração de matriz em java 
Java :: get tfidf score for a sentence 
Java :: array to map java2 
Java :: calculate prime factors of a number java 
Java :: how to set scroll to bottom jscrollpane 
Java :: join array java 
Java :: javafx action event enter key 
Java :: java selenium wait 
Java :: java remove file extension from file name 
Java :: read jar manifest 
Java :: centos install openjdk 11 
Java :: java how to get deltaTime 
Java :: java how to create india currency 
Java :: how to check keyboard is open or not in android 
Java :: list of longs to comma separeated string java 
Java :: java copy list 
Java :: dreamworks studio recent movies 
Java :: java number padding zeros 
Java :: java 2d game tutorial 
Java :: lakshya 
Java :: how to make a bot to wait in jda 
Java :: convert char to string java 
Java :: java verify string is hexadecimal 
Java :: setText int java 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =