Validates given email string using android.util.Patterns#EMAIL_ADDRESS pattern - Android java.util.regex

Android examples for java.util.regex:Email Pattern

Description

Validates given email string using android.util.Patterns#EMAIL_ADDRESS pattern

Demo Code


//package com.java2s;
import android.text.TextUtils;
import android.util.Patterns;

public class Main {
    /**//from   w  w  w  . j  a  v  a  2s  .co  m
     * Validates given email string using {@link android.util.Patterns#EMAIL_ADDRESS} pattern
     *
     * @param email to validate
     * @return true if email is valid, otherwise false
     */
    public static boolean isValidEmail(final String email) {
        if (TextUtils.isEmpty(email)) {
            return false;
        }

        return Patterns.EMAIL_ADDRESS.matcher(email).matches();
    }
}

Related Tutorials