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 Boolean isMobileNo(String str) {
    Pattern pattern = Pattern.compile("1[0-9]{10}");
    Matcher matcher = pattern.matcher(str);
    if (matcher.matches()) {
        return true;
    } else {/*from  w w  w . j a va  2s  . co  m*/
        return false;
    }
}

From source file:Main.java

public static boolean matchMobilNo(String num) {
    if (TextUtils.isEmpty(num)) {
        return false;
    }/*from w w  w. j a  v a2 s  . c  om*/
    String reg = "^((13[0-9])|(14[5,7])|(15[^4,\\D])|(17[0,6,7])|(18[0-9]))\\d{8}$";
    Pattern pattern = Pattern.compile(reg);
    Matcher matcher = pattern.matcher(num);
    boolean flag = matcher.matches();
    return flag;
}

From source file:Main.java

public static boolean isValidEmail(String email) {
    boolean flag = false;
    try {//from w w w.j av a2s  .c  om
        String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(email);
        flag = matcher.matches();
    } catch (Exception e) {
        flag = false;
    }

    return flag;

}

From source file:Main.java

public static boolean isEmailLegal(String email) {
    if (TextUtils.isEmpty(email))
        return false;

    final String REGEXP = "^([a-z0-9\\-_.+]+)@([a-z0-9\\-]+[.][a-z0-9\\-.]+)$";
    Pattern p = Pattern.compile(REGEXP);
    Matcher m = p.matcher(email.toLowerCase());
    return m.matches();
}

From source file:Main.java

public static boolean validatePassWord(String password) {
    boolean flag;
    try {//from   w w w  .j a va  2s .c om
        String check = "^[A-Za-z0-9]{6,16}$";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(password);
        flag = matcher.matches();
    } catch (Exception e) {
        flag = false;
    }
    return flag;
}

From source file:Main.java

public static boolean isValidIpAddress(String input) {
    String ipv4Regex = "(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])";
    String ipv6Regex = "([0-9a-f]{1,4}:){7}([0-9a-f]){1,4}";
    Pattern ipv4Pattern = Pattern.compile(ipv4Regex);
    Pattern ipv6Pattern = Pattern.compile(ipv6Regex);

    Matcher ipv4Matcher = ipv4Pattern.matcher(input);
    if (ipv4Matcher.matches())
        return true;
    Matcher ipv6Matcher = ipv6Pattern.matcher(input);
    return ipv6Matcher.matches();
}

From source file:Main.java

public static boolean isPhoneNumberValid(String phoneNumber) {
    if ((phoneNumber == null) || (phoneNumber.trim().equals(""))) {
        return false;
    }/*from  w w w.  j  av  a2  s  . co m*/
    boolean isValid = false;
    String expression_r_r = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{5})$";
    Pattern pattern = Pattern.compile(expression_r_r);
    Matcher matcher = pattern.matcher(phoneNumber);
    if (matcher.matches()) {
        isValid = true;
    }
    return isValid;
}

From source file:Main.java

public static boolean isEmail(String email) {

    if (TextUtils.isEmpty(email))
        return false;

    String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";

    Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(email);

    return matcher.matches();

}

From source file:Main.java

public static boolean isNumber(String numStr) {
    if (TextUtils.isEmpty(numStr))
        return false;
    Pattern pattern = Pattern.compile("[0-9]*");
    Matcher match = pattern.matcher(numStr);
    return match.matches();
}

From source file:Main.java

public static CharSequence[] parseDescription(CharSequence string) {
    Matcher matcher = PAT_ATLASQUEST.matcher(string);
    if (matcher.matches())
        return new CharSequence[] { "LB" + matcher.group(2).trim(), matcher.group(1).trim() };
    return new CharSequence[] { string, "" };
}