Example usage for java.util.regex Pattern compile

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

Introduction

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

Prototype

public static Pattern compile(String regex) 

Source Link

Document

Compiles the given regular expression into a pattern.

Usage

From source file:Main.java

public static boolean isValidUserName(String userName) {
    Pattern p = Pattern.compile("^[\u4E00-\u9FA50-9a-zA-Z_-]{0,}$");
    Matcher m = p.matcher(userName);
    return m.matches();
}

From source file:Main.java

public static boolean isDate(String strDate) {
    Pattern pattern = Pattern.compile(
            "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$");
    Matcher m = pattern.matcher(strDate);
    return m.matches();
}

From source file:Main.java

public static boolean checkIPAddress(String ip) {
    Pattern pattern = Pattern.compile(
            "\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b");
    Matcher matcher = pattern.matcher(ip);
    return matcher.matches();
}

From source file:Main.java

public static boolean isNumeric(String str) {
    Pattern pattern = Pattern.compile("[0-9]*");
    Matcher isNum = pattern.matcher(str);
    if (!isNum.matches())
        return false;
    return true;/*  w w  w.ja v a 2 s . c om*/
}

From source file:Main.java

public static boolean isValidString(String str) {
    Pattern pattern = Pattern.compile("^(?:[\\u4e00-\\u9fa5]*\\w*\\s*)+$");
    Matcher matcher = pattern.matcher(str);
    return matcher.matches();
}

From source file:Main.java

public static boolean checkEmail(String email) {

    Pattern pattern = Pattern.compile("^\\w+([-.]\\w+)*@\\w+([-]\\w+)*\\.(\\w+([-]\\w+)*\\.)*[a-z]{2,3}$");
    Matcher matcher = pattern.matcher(email);
    return matcher.matches();
}

From source file:Main.java

public static boolean checkEmailIsOK(String emailStr) {
    Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}");
    Matcher m = p.matcher(emailStr);
    return m.matches();
}

From source file:Main.java

public static boolean checkEmailEnable(String email) {
    return Pattern.compile(
            "^([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})(\\]?)$")
            .matcher(email).matches();/*from  w  ww  .j a  v a  2 s.  co  m*/
}

From source file:Main.java

public static boolean isNormalName(String name) {
    Pattern p = Pattern.compile("([A-Za-z0-9\u4E00-\u9FA5]+)");
    Matcher m = p.matcher(name);//  w  w  w.  j av  a2s  .  c  o m
    if (m.matches()) {
        return true;
    } else {
        return false;
    }
}

From source file:Main.java

public static boolean isAccountStandard(String uname) {
    Pattern p = Pattern.compile("[A-Za-z0-9_]+");
    Matcher m = p.matcher(uname);
    return m.matches();
}