is Email by your own regex - Android java.util.regex

Android examples for java.util.regex:Email Pattern

Description

is Email by your own regex

Demo Code


//package com.java2s;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static boolean isEmail(String email) {
        boolean isValid = false;
        String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
        CharSequence inputStr = email;
        Pattern pattern = Pattern.compile(expression,
                Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(inputStr);
        if (matcher.matches()) {
            isValid = true;//from   w  ww .  j  av  a 2 s. c om
        }
        return isValid;
    }
}

Related Tutorials