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 eMailValidation(String emailstring) {
    if (null == emailstring || emailstring.length() == 0) {
        return false;
    }/*ww w.  j a  v  a  2s  .c  om*/
    Pattern emailPattern = Pattern.compile(
            "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
    Matcher emailMatcher = emailPattern.matcher(emailstring);
    return emailMatcher.matches();
}

From source file:Main.java

public static boolean isLinkAvailable(String link) {
    Pattern pattern = Pattern.compile(
            "^(http://|https://)?((?:[A-Za-z0-9]+-[A-Za-z0-9]+|[A-Za-z0-9]+)\\.)+([A-Za-z]+)[/\\?\\:]?.*$",
            Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(link);
    if (matcher.matches()) {
        return true;
    }//  w  w  w . ja v a 2  s.co m
    return false;
}

From source file:Main.java

public static boolean checkEmail(String emailStr) {
    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(emailStr.trim());
    return matcher.matches();
}

From source file:Main.java

public static String getHrefInnerHtml(String href) {
    if (isEmpty(href)) {
        return "";
    }//from  w  w  w  .  ja va  2  s.co  m

    String hrefReg = ".*<[\\s]*a[\\s]*.*>(.+?)<[\\s]*/a[\\s]*>.*";
    Pattern hrefPattern = Pattern.compile(hrefReg, Pattern.CASE_INSENSITIVE);
    Matcher hrefMatcher = hrefPattern.matcher(href);
    if (hrefMatcher.matches()) {
        return hrefMatcher.group(1);
    }
    return href;
}

From source file:com.cy.driver.common.util.ValidateUtil.java

/**
 * ????// ww w  .j  av a2 s  .c  o m
 * @return false:?; true:
 * */
public static boolean validateTelePhone(String telephone) {
    if (StringUtils.isEmpty(telephone)) {
        return false;
    }
    String regx = "^((13[0-9])|(15[^4,\\D])|(18[0-9])|(17[0-9])|(14[0-9]))\\d{8}$";
    Pattern pattern = Pattern.compile(regx);
    Matcher macher = pattern.matcher(telephone);
    return macher.matches();
}

From source file:Main.java

public static final boolean isValidPassword(final String password) {
    boolean result = false;
    if (password != null) {
        Pattern pattern = Pattern
                .compile("^[\\@A-Za-z0-9\\!\\#\\$\\%\\^\\&\\*\\.\\~\\*\\(\\)\\+\\-\\=\\_]{6,20}$");
        Matcher matcher = pattern.matcher(password.trim());
        result = matcher.matches();
    }//from ww w  .j a  v  a  2  s.  c  o m
    return result;
}

From source file:Main.java

/**
 * Check if the name matches the expected format for a hub Bluetooth name.
 * @param name/*from  ww  w  . j ava2 s . c om*/
 * @return true if the pattern matches, false if it doesn't.
 */
public static boolean isValidName(String name) {
    Matcher matcher = NAME_PATTERN.matcher(name);
    return matcher.matches();
}

From source file:Main.java

public static boolean isValidEmail(String number) {
    Matcher matcher = emailPattern.matcher(number);
    return matcher.matches();
}

From source file:Main.java

public static String getYoutubeVideoId(String youtubeUrl) {
    String video_id = "";
    if (youtubeUrl != null && youtubeUrl.trim().length() > 0 && youtubeUrl.startsWith("http")) {

        String expression = "^.*((youtu.be" + "\\/)"
                + "|(v\\/)|(\\/u\\/w\\/)|(embed\\/)|(watch\\?))\\??v?=?([^#\\&\\?]*).*"; // var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
        CharSequence input = youtubeUrl;
        Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(input);
        if (matcher.matches()) {
            String groupIndex1 = matcher.group(7);
            if (groupIndex1 != null && groupIndex1.length() == 11)
                video_id = groupIndex1;//from   ww w.j  a v  a2  s.c  o  m
        }
    }
    return video_id;
}

From source file:Main.java

public static int verifyPassword(@NonNull String password) {

    int length = password.length();
    if (length < 6 || length > 18) {
        return VERIFY_LENGTH_ERROR;
    }//from   ww  w .  jav  a  2 s  . c om

    String regex = "^\\w+$";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(password);

    if (!matcher.matches())
        return VERIFY_TYPE_ERROR;
    return VERIFY_SUCCESS;
}