Special thanks to Bob Matsuoka for this one.

This is needed so often it should be available on every street corner.

[Thanks to Jason Bell, who noted that it should support mixed-case.]

“^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$”

Here’s the Java code:

    /**
     * Uses a basic regular expression match to insure that
     * the given email address "looks" like it should be valid.
     * @param email
     * @return true if valid, else false
     */
    public static boolean isValidEmailAddress(String email)
    {
        String regex = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$";
        return email.matches(regex);
    }

No related posts.