Check if string is Email using Regex - Android java.util.regex

Android examples for java.util.regex:Email Pattern

Description

Check if string is Email using Regex

Demo Code


//package com.java2s;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private static boolean isEmail(String text) {
        String reg = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        Pattern regex = Pattern.compile(reg);
        Matcher matcher = regex.matcher(text);
        return matcher.matches();

    }/*from  w w  w . ja  va 2  s. co  m*/
}

Related Tutorials