Example usage for java.lang String matches

List of usage examples for java.lang String matches

Introduction

In this page you can find the example usage for java.lang String matches.

Prototype

public boolean matches(String regex) 

Source Link

Document

Tells whether or not this string matches the given regular expression.

Usage

From source file:Main.java

public static boolean isAlpha(String name) {
    String pattern = "^\\d*[a-zA-Z][a-zA-Z\\d]*$";
    return name.matches(pattern);
}

From source file:Main.java

public static boolean checkMobile(String mobile) {
    String mobilePattern = "^1[3,4,5,8]\\d{9}$";
    return mobile.matches(mobilePattern);
}

From source file:Main.java

public static boolean isValidBillNum(String str) {
    return str != null && str.length() >= 8 && str.length() <= 32 && str.matches("[A-Za-z0-9]+");
}

From source file:Main.java

public static boolean isOrgCode(String OrgCode) {
    String regex = "[a-zA-Z0-9]{8}-[a-zA-Z0-9]";
    return OrgCode.matches(regex);
}

From source file:com.semicolonapps.onepassword.ItemFactory.java

public static Item create(JSONArray parts, File baseDir) {
    RawItem raw = new RawItem(parts);

    String type = raw.getType();

    if (type.matches(LOGIN)) {
        return new LoginItem(raw);
    } else if (type.matches(IDENTITY)) {
        return new IdentityItem(raw);
    } else if (type.matches(NOTE)) {
        return new NoteItem(raw);
    } else if (type.matches(PASSWORD)) {
        return new PasswordItem(raw);
    } else if (type.matches(WALLET)) {
        return new WalletItem(raw);
    } else if (type.matches(SOFTWARE)) {
        return new LicenseItem(raw);
    }//from w  ww  .  j a va 2  s .  co  m

    return null;
}

From source file:Main.java

public static int getStringUnicodeLength(String value) {
    int valueLength = 0;
    String chinese = "[\u4e00-\u9fa5]";
    // Judge the unicodelength is 1 or 2
    for (int i = 0; i < value.length(); i++) {

        String temp = value.substring(i, i + 1);

        if (temp.matches(chinese)) {

            valueLength += 2;/*from w w  w  . ja v  a2 s.  co m*/
        } else {

            valueLength += 1;
        }
    }

    return valueLength;
}

From source file:Main.java

public static boolean isValidPhoneNumber(String phoneNumber) {
    String regex = "^07[0-9]{8}$"; //Romania :)
    return phoneNumber.matches(regex);
}

From source file:Main.java

public static boolean isHexAnd32Byte(String hexString, Context context) {
    if (hexString.matches("[0-9A-Fa-f]+") == false) {
        // Error, not hex.
        // Toast.makeText(context, R.string.info_not_hex_data,
        // Toast.LENGTH_LONG).show();
        return false;
    }//from  w w w. j av  a  2  s  .c o  m
    if (hexString.length() != 64) {
        // Error, not 16 byte (64 chars).
        // Toast.makeText(context, R.string.info_not_16_byte,
        // Toast.LENGTH_LONG).show();
        return false;
    }
    return true;
}

From source file:Main.java

public static int getStringLength(String value) {
    if (null == value || "".equals(value)) {
        return 0;
    } else {//from ww w .  jav  a 2 s . c  om
        int valueLength = 0;
        String chinese = "[\u4e00-\u9fa5]";
        for (int i = 0; i < value.length(); i++) {
            String temp = value.substring(i, i + 1);
            if (temp.matches(chinese)) {
                valueLength += 2;
            } else {
                valueLength += 1;
            }
        }
        return valueLength;
    }

}

From source file:Main.java

public static boolean isHexAnd48Byte(String hexString, Context context) {
    if (hexString.matches("[0-9A-Fa-f]+") == false) {
        // Error, not hex.
        // Toast.makeText(context, R.string.info_not_hex_data,
        // Toast.LENGTH_LONG).show();
        return false;
    }//from   w  w w  .j a va 2s .co  m
    if (hexString.length() != 96) {
        // Error, not 16 byte (32 chars).
        // Toast.makeText(context, R.string.info_not_16_byte,
        // Toast.LENGTH_LONG).show();
        return false;
    }
    return true;
}