Example usage for java.util.regex Pattern matches

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

Introduction

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

Prototype

public static boolean matches(String regex, CharSequence input) 

Source Link

Document

Compiles the given regular expression and attempts to match the given input against it.

Usage

From source file:Main.java

public static boolean checkBirthday(String birthday) {
    String regex = "\\d{4}([-./])\\d{1,2}([-./])\\d{1,2}";
    return Pattern.matches(regex, birthday);
}

From source file:Main.java

public static boolean checkPlateNumber(String plateNumber) {
    String regex = "^[\u4e00-\u9fa5|WJ]{1}[A-Z0-9]{6}$";
    return Pattern.matches(regex, plateNumber);
}

From source file:Main.java

public static int HextoColor(String color) {
    // #ff00CCFF//from ww  w . j a v  a2  s.co m
    String reg = "#[a-f0-9A-F]{8}";
    if (!Pattern.matches(reg, color)) {
        color = "#00ffffff";
    }

    return Color.parseColor(color);
}

From source file:Main.java

public static boolean isCorrectIDCardNumber(String idCardNumber) {
    return !TextUtils.isEmpty(idCardNumber)
            && Pattern.matches("(\\d{14}[0-9a-zA-Z])|(\\d{17}[0-9a-zA-Z])", idCardNumber);
}

From source file:Main.java

public static boolean isEmail(String email) {
    String emailPattern = "[a-zA-Z0-9][a-zA-Z0-9._-]{2,16}[a-zA-Z0-9]@[a-zA-Z0-9]+.[a-zA-Z0-9]+";
    boolean result = Pattern.matches(emailPattern, email);
    return result;
}

From source file:Main.java

public static boolean IsMobileNum(String mobile) {
    String reg = "/^(((13)[5-9]{1})|((15)[0,1,2,7,8,9]{1})|(188))[0-9]{8}$|(^((134)[0-8]{1})[0-9]{7}$)/";
    return Pattern.matches(reg, mobile);
}

From source file:Main.java

public static boolean checkURL(String url) {
    String regex = "(https?://(w{3}\\.)?)?\\w+\\.\\w+(\\.[a-zA-Z]+)*(:\\d{1,5})?(/\\w*)*(\\??(.+=.*)?(&.+=.*)?)?";
    return Pattern.matches(regex, url);
}

From source file:Main.java

public static boolean checkIdentityNo(String identityNo) {
    return identityNo == null || "".equals(identityNo) ? false
            : Pattern.matches("(^\\d{15}$)|(\\d{17}(?:\\d|x|X)$)", identityNo);
}

From source file:Main.java

public static boolean checkMobile(String mobile) {
    //String regex = "1[34578]\\d{9}$";
    String regex2 = "^(((1[3,8][0-9])|(17(0|3|[5-8]))|(14[4,5,7,9])|(15([0-3]|[5-9])))\\d{8})$";
    return Pattern.matches(regex2, mobile);
}

From source file:Main.java

public static int HextoColor(String color) {
    // #00000000 - #ffffffff
    String reg = "#[a-f0-9A-F]{8}";
    if (!Pattern.matches(reg, color)) {
        color = "#ffffffff";
    }//  w  w w.  ja v  a  2 s .com
    return Color.parseColor(color);
}