Android Email String Validate checkMail(String email)

Here you can find the source of checkMail(String email)

Description

check Mail

Declaration

public static boolean checkMail(String email) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static boolean checkMail(String email) {
        String input = "@sun.com";
        // Checks for email addresses starting with
        // inappropriate symbols like dots or @ signs.
        Pattern p = Pattern.compile("^\\.|^\\@");
        Matcher m = p.matcher(input);
        if (m.find())
            return false;
        // Checks for email addresses that start with
        // www. and prints a message if it does.
        p = Pattern.compile("^www\\.");
        m = p.matcher(input);/*from  ww  w  .  ja  va 2s. c om*/
        if (m.find()) {
            return false;
        }
        p = Pattern.compile("[^A-Za-z0-9\\.\\@_\\-~#]+");
        m = p.matcher(input);
        StringBuffer sb = new StringBuffer();
        boolean result = m.find();
        boolean deletedIllegalChars = false;

        while (result) {
            deletedIllegalChars = true;
            m.appendReplacement(sb, "");
            result = m.find();
        }

        // Add the last segment of input to the new String
        m.appendTail(sb);
        input = sb.toString();

        if (deletedIllegalChars) {
            return false;
        }

        return true;
    }
}

Related

  1. isValidEmailAddress(String email)
  2. isEmailValid(CharSequence email)
  3. isEmail(String email)
  4. isEmail(String str)
  5. isEmailValid(String email)
  6. isEmail(String s)
  7. isValidEmail(String email)
  8. isValidEmail(CharSequence target)
  9. emailValidator(final String mailAddress)