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 isValidCardNumber(String cardNumber) {
    boolean isValid = false;

    String expression = "^.{12,16}$";
    CharSequence inputStr = cardNumber;

    Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(inputStr);
    if (matcher.matches()) {
        isValid = true;/*from  w  w w  . j  a  v a 2s .  c o  m*/
    }
    return isValid;
}

From source file:Main.java

public static boolean isUserNameValid(String username) {
    boolean isValid = false;

    String expression = "^[a-zA-Z0-9_-]{5,10}$";
    CharSequence inputStr = username;

    Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(inputStr);
    if (matcher.matches()) {
        isValid = true;/*from w w w . j a  v a2 s.c  om*/
    }
    return isValid;
}

From source file:Main.java

public static boolean isNumber(String str) {
    Pattern pattern = Pattern.compile("[0-9]*");
    java.util.regex.Matcher match = pattern.matcher(str);
    if (match.matches() == false) {
        return false;
    } else {//from  w  w w.  j a va  2  s.c  o m
        return true;
    }
}

From source file:Main.java

public static boolean validateString(String s) {
    boolean tag = true;
    final String pattern1 = "^[a-zA-Z0-9]{6,16}$";
    Pattern pattern = Pattern.compile(pattern1);
    Matcher matcher = pattern.matcher(s);
    if (s == null || !matcher.matches()) {
        tag = false;//from w ww. ja  va 2 s.c om
    }
    return tag;
}

From source file:Main.java

public static boolean isEmailFormat(String email) {
    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");
    boolean isMatched = matcher.matches();
    return isMatched;
}

From source file:Main.java

public static boolean isEmailValid(String email) {
    boolean isValid = false;

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

    Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(inputStr);
    if (matcher.matches()) {
        isValid = true;/*ww  w  . j  av a2  s  .  c  o m*/
    }
    return isValid;
}

From source file:Main.java

public static boolean isNormalCharValid(String mChar) {
    boolean isValid = false;

    String expression = "\\:*?<>|\"\n\t";

    CharSequence inputStr = mChar;
    Pattern pattern = Pattern.compile(expression);
    Matcher matcher = pattern.matcher(inputStr);
    if (matcher.matches()) {
        isValid = true;//  w  w  w . j a  va  2s  .  c  o  m
    }
    return isValid;
}

From source file:Main.java

public static boolean checkEmail(String email) {
    boolean flag = false;
    try {/*  w ww.  j a v a2s  . com*/
        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 isNumeric(String str) {
    boolean isMatches = false;
    Pattern pattern = Pattern.compile("[0-9]*");
    Matcher isNum = pattern.matcher(str);
    if (isNum.matches()) {
        isMatches = true;// w  w  w . ja  v a2 s. co m
    }
    return isMatches;
}

From source file:Main.java

public static boolean validateAntifakeId(String s) {
    boolean tag = true;
    final String pattern1 = "^[0-9]{18,18}$";
    Pattern pattern = Pattern.compile(pattern1);
    Matcher matcher = pattern.matcher(s);
    if (s == null || !matcher.matches()) {
        tag = false;/*from  w  w  w.ja v  a 2  s  .c o  m*/
    }
    return tag;
}