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 isAlphaNumeric(String s) {

    String pattern = "^[a-zA-Z0-9 ]*$";
    if (s.matches(pattern)) {
        return true;
    }/*  w w w.  j a v  a2  s .c o m*/
    return false;
}

From source file:Main.java

public static boolean isIDCard(String IDStr) {
    String regx = "\\d{15}|\\d{17}[\\dXx]";
    return IDStr.matches(regx);
}

From source file:Main.java

public static int lastIndexOfChinese(String text) {
    char[] charArray = text.toCharArray();
    int index = -1;
    for (int i = 0; i < charArray.length; i++) {
        String tempC = Character.toString(charArray[i]);
        if (tempC.matches("[\u4E00-\u9FA5]+")) {
            index = i;/*from ww w  . j a v  a2s.  c om*/
        }
    }
    return index;
}

From source file:Main.java

/**
 * Validates the email./* w w w  .ja  v  a 2s .  c o  m*/
 * @param email - Email.
 * @return - True (if is valid) or False (otherwise).
 */
public static boolean validateEmail(String email) {
    if (email == null || email.length() == 0 || !email.matches(
            "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"))
        return false;

    return true;
}

From source file:mx.jalan.Utils.KeyUtils.java

public static boolean isLong(String strLong) {
    if (!strLong.matches("(?<=\\s|^)\\d+(?=\\s|$)")) {
        return false;
    }/*from  w ww  .  ja  v  a2  s .c o m*/

    if (!NumberUtils.isCreatable(strLong)) {
        return false;
    }

    return true;
}

From source file:Main.java

public static boolean isNum(final String strNum) {
    return strNum.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
}

From source file:com.skcraft.launcher.builder.BuilderUtils.java

public static List<Compressor> getCompressors(String repoUrl) {
    if (repoUrl.matches("^https?://files.minecraftforge.net/maven/")) {
        return Lists.newArrayList(new Compressor("xz", CompressorStreamFactory.XZ),
                new Compressor("pack", CompressorStreamFactory.PACK200));
    } else {// w  w  w . ja  v a2  s  . c  om
        return Collections.emptyList();
    }
}

From source file:Main.java

public static boolean isValidMobiNumber(String paramString) {
    String regex = "^1[3,5,7,8]\\d{9}$";
    if (paramString.matches(regex)) {
        return true;
    }//from   w ww .j  av  a2  s .  c o m
    return false;
}

From source file:Main.java

public static boolean checkPassword(String password) {
    String format = "^[a-zA-Z0-9]{6,}$";
    if (password.matches(format)) {
        return true;
    } else {// w  w  w .ja va  2  s . c  om
        return false;
    }
}

From source file:Main.java

/**
 * Is the given commit SHA-1 valid?//from   w  ww.j  ava 2  s.  c  o m
 *
 * @param sha
 * @return true if valid, false otherwise
 */
public static boolean isValidCommit(final String sha) {
    return !TextUtils.isEmpty(sha) && sha.matches("[a-fA-F0-9]+");
}