is a valid Email address by regular expression - Android java.util.regex

Android examples for java.util.regex:Email Pattern

Description

is a valid Email address by regular expression

Demo Code

import android.content.Context;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static boolean isEmail(String str) {
        try {/* ww w  . java 2  s.  co  m*/
            Pattern pattern = Pattern
                    .compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");

            Matcher matcher = pattern.matcher(str);
            return matcher.matches();
        } catch (Throwable e) {
        }
        return false;
    }

}

Related Tutorials