Example usage for java.util.regex Matcher matches

List of usage examples for java.util.regex Matcher matches

Introduction

In this page you can find the example usage for java.util.regex Matcher matches.

Prototype

public boolean matches() 

Source Link

Document

Attempts to match the entire region against the pattern.

Usage

From source file:Main.java

public static String getYoutubeVideoId(String url) {
    Pattern pattern = Pattern.compile("^https?://.*(?:youtu.be/|v/|u/\\w/|embed/|watch?v=)([^#&?]*).*$",
            Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(url);
    if (!matcher.matches())
        throw new IllegalArgumentException("Regex fail. not matched. Url: " + url);

    return matcher.group(1);
}

From source file:Main.java

public static boolean checkPassword(String password) {
    Pattern pattern = Pattern.compile(".*[a-zA-Z].*[0-9]|.*[0-9].*[a-zA-Z]");
    //Pattern pattern = Pattern.compile("^[A-Za-z0-9]{6,20}$");
    Matcher matcher = pattern.matcher(password);
    return matcher.matches();
}

From source file:Main.java

public static boolean isMobileNumber(String phoneNumber) {
    Pattern pattern = Pattern.compile("^(0|86|17951)?(13[0-9]|15[0-9]|17[0-9]|18[0-9]|14[0-9])[0-9]{8}$");
    Matcher matcher = pattern.matcher(phoneNumber);
    return matcher.matches();
}

From source file:Main.java

public static boolean isEmailValid(String email) {
    final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
            + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
    Pattern pattern = Pattern.compile(EMAIL_PATTERN);
    Matcher matcher = pattern.matcher(email);
    return matcher.matches();
}

From source file:Main.java

public static boolean isNumeric(String str) {
    if ("".equals(str))
        return false;
    Pattern pattern = Pattern.compile("[0-9]*");
    Matcher isNum = pattern.matcher(str);
    if (!isNum.matches()) {
        return false;
    }/*from   ww  w . j a va 2s  .  c  o m*/
    return true;
}

From source file:Main.java

public static boolean isMobileNO(String mobiles) {
    Pattern p = Pattern.compile("^((13[0-9])|(15[^4,//D])|(18[0,5-9]))//d{8}$");
    Matcher m = p.matcher(mobiles);
    System.out.println(m.matches() + "---");
    return m.matches();
}

From source file:Main.java

public static boolean checkNumber(String username) {

    Pattern pattern = Pattern.compile("^[0-9]+$");
    Matcher matcher = pattern.matcher(username);
    return matcher.matches();
}

From source file:Main.java

public static boolean verifyEmail(String email) {
    String str = "^([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})(\\]?)$";
    Pattern pattern = Pattern.compile(str);
    Matcher matcher = pattern.matcher(email);
    return matcher.matches();
}

From source file:Main.java

public static boolean isShort(String password) {
    if (password == null || password.equals("")) {
        Log.d(TAG, "password is null");
        return false;
    }/*  www  .  ja v  a 2  s  .  co m*/
    String strPattern = "^[0-9A-Za-z]{6,}$";
    Pattern p = Pattern.compile(strPattern);
    Matcher m = p.matcher(password);
    return m.matches();
}

From source file:Main.java

public static boolean isCnEnNumCorrect(final String content) {
    String rex = "^[\u4e00-\u9fa5a-zA-Z0-9]+$";
    Pattern pattern = Pattern.compile(rex);
    Matcher matcher = pattern.matcher(content);
    return matcher.matches();
}