Java Email Validate isMobilesOrEmail(String str)

Here you can find the source of isMobilesOrEmail(String str)

Description

is Mobiles Or Email

License

Apache License

Declaration

public static boolean isMobilesOrEmail(String str) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {

    public static boolean isMobilesOrEmail(String str) {
        if (isMobileNO(str) || isEmail(str)) {
            return true;
        }/* ww  w .jav  a  2  s .c om*/
        return false;
    }

    public static boolean isMobileNO(String mobiles) {
        String regex = "^((13[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\\d{8}$";
        return match(regex, mobiles);
    }

    public static boolean isEmail(String str) {
        String regex = "^([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})(\\]?)$";
        return match(regex, str);
    }

    private static boolean match(String regex, String str) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }
}

Related

  1. isEmailValid(String email)
  2. isEmailValid(String email)
  3. isEmailValid(String emailAddress)
  4. isLegarEmail(String email)
  5. isMail(String email)
  6. isStrEmailAddress(String str)
  7. isValidEmail(final String email)
  8. isValidEmail(final String email)
  9. isValidEmail(String email)