Determine if the given address is a valid email address using regex - Java java.util.regex

Java examples for java.util.regex:Match Email

Description

Determine if the given address is a valid email address using regex

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String address = "java2s.com";
        System.out.println(isEmail(address));
    }/*from ww w .j  av  a 2  s  . com*/

    private final static String REG_EX_EMAIL = "[a-zA-Z]\\w+(.\\w+)*@\\w+(.[0-9a-zA-Z]+)*.[a-zA-Z]{2,4}";

    /**
     * Determine if the given address is a valid email address
     * @param address the address to validate
     * @return {Boolean} whether or not address is a valid email
     * @method isEmail
     * @static
     */
    public static boolean isEmail(String address) {
        return address != null && address.matches(REG_EX_EMAIL);
    }
}

Related Tutorials