check if a string is a valid Email address - Android java.util.regex

Android examples for java.util.regex:Email Pattern

Description

check if a string is a valid Email address

Demo Code

import android.util.Log;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static boolean checkEmail(String email) {

        Pattern pattern = Pattern
                .compile("^\\w+([-.]\\w+)*@\\w+([-]\\w+)*\\.(\\w+([-]\\w+)*\\.)*[a-z]{2,3}$");
        Matcher matcher = pattern.matcher(email);
        if (matcher.matches()) {
            return true;
        }/*w ww. java  2s  .com*/
        return false;
    }

}

Related Tutorials