Example usage for java.util.regex Pattern matches

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

Introduction

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

Prototype

public static boolean matches(String regex, CharSequence input) 

Source Link

Document

Compiles the given regular expression and attempts to match the given input against it.

Usage

From source file:jp.co.ctc_g.jse.core.validation.util.Validators.java

/**
 * ????????????????/*from   w w  w. j  a v  a2 s  .co m*/
 * @param regex ??
 * @param suspect 
 * @return ???true
 */
public static boolean isMatches(String regex, CharSequence suspect) {
    return Pattern.matches(regex, suspect);
}

From source file:ambroafb.general.AnnotiationUtils.java

private static boolean checkValidationForContentPatternAnnotation(Field field, Object currSceneController) {
    boolean contentIsCorrect = false;
    Annotations.ContentPattern annotation = field.getAnnotation(Annotations.ContentPattern.class);

    Object[] typeAndContent = getNodesTypeAndContent(field, currSceneController);

    if (!Pattern.matches(annotation.value(), (String) typeAndContent[1])) {
        changeNodeTitleLabelVisual((Node) typeAndContent[0], annotation.explain());
    } else {/*from w ww  . j  a v  a  2  s. c om*/
        changeNodeTitleLabelVisual((Node) typeAndContent[0], "");
        contentIsCorrect = true;
    }
    return contentIsCorrect;
}

From source file:mobi.jenkinsci.net.UrlPath.java

/**
 *
 * @param __path The path to compare with this path I.e. if this.path =
 *        res1/res2/res3 and current node path is res1/res2 : the method
 *        should return true if this.path = res1/res2/res3 and current node
 *        path is re ss1/res4 : the method should return false
 * @return True if the given path is part of this path
 *///from  ww w.j av a2  s  .c  o  m
public boolean isFollowingPath(String currentNodePath) {

    if (currentNodePath == null) {
        return false;
    }

    if (!currentNodePath.endsWith("/")) {
        currentNodePath = currentNodePath + "/";
    }

    if (!path.endsWith("/")) {
        path = path + "/";
    }

    final String currentNodePathPattern = "/?" + Matcher.quoteReplacement(currentNodePath) + ".*";
    return Pattern.matches(currentNodePathPattern, path);
}

From source file:br.com.nordestefomento.jrimum.vallia.AbstractCPRFValidator.java

/**
 * <p>/*from   w  w w  . jav a  2 s .c om*/
 * Define se os parmetros vlidos em relao a nulidade e formato de CPRF.
 * </p>
 * 
 * @param codigoDoCadastro
 * @param tipoDeCadastro
 * @return indicao de aprovao
 * @throws IllegalArgumentException
 * 
 * @since 0.2
 */

public static boolean isParametrosValidos(String codigoDoCadastro, TipoDeCPRF tipoDeCadastro)
        throws IllegalArgumentException {

    boolean isValido = false;

    if (isNotNull(codigoDoCadastro) && isNotNull(tipoDeCadastro)) {

        if (Pattern.matches(REGEX_CADASTRO, codigoDoCadastro)) {

            isValido = true;

        } else {

            throw new IllegalArgumentException(
                    "O cadastro est em um tamanho incorreto ou no exsite: [ " + codigoDoCadastro + " ]");
        }
    } else {

        throw new IllegalArgumentException("O tipo de cadastro est incorreto: [ " + tipoDeCadastro
                + " ] ou o cadastro no exsite: [ " + codigoDoCadastro + " ]");
    }

    return isValido;
}

From source file:gov.nih.nci.security.util.StringUtilities.java

public static boolean checkPatternMatches(String password, String pattern) {
    Pattern.quote(password);/*  ww w  .j  a  va2  s.  c  o  m*/
    if (Pattern.matches(pattern, password))
        return true;
    else
        return false;
}

From source file:edu.lafayette.metadb.web.metadata.UpdateAdminDescMetadata.java

private static boolean isValidSearchDate(String value) {
    //must be at least yyyy
    if (value.length() == 0)
        return true;
    if (value.length() < 4)
        return false;
    return (Pattern.matches("\\d\\d\\d\\d(([-](0[1-9]|1[012])(([-](0[1-9]|[12][0-9]|3[01]))?))?)", value))
            || (Pattern.matches("\\d\\d\\d\\d[-]\\d\\d\\d\\d", value));
}

From source file:com.huateng.ebank.business.common.service.CommonService.java

/**
 *
 * Description: ???23893788-0//from www .ja va 2 s. c om
 *
 * Modified by Robin Suo For Jira BMS-2329 ???8??
 *
 * @param no ??
 * @return ?boolean
 * @author mengyf
 * @version v1.0,2008-11-19
 */
public boolean checkOrgCode(String no) {
    // ??
    if (StringUtils.isBlank(no)) {
        return false;
    }

    // 
    String orgCode = StringUtils.trimToEmpty(no);

    // ??10?? ?8?9???10??
    if (!Pattern.matches("^[A-Z0-9]{8}\\-[\\d{1}|X]$", orgCode)) {
        return false;
    }

    int[] tempInt = new int[8];
    int[] factor = { 3, 7, 9, 10, 5, 8, 4, 2 };

    int sum = 0;
    if (orgCode.charAt(8) != 45) {
        return false;
    }
    for (int i = 0; i < 10; i++) {
        int c = orgCode.charAt(i);
        if (c <= 122 && c >= 97) {
            return false;
        }
    }

    /*
     * Blocked by Robin Suo For Jira BMS-2329 int fir_value =
     * orgCode.charAt(0); int sec_value = orgCode.charAt(1);
     *
     * if (fir_value >= 65 && fir_value <= 90) { tempInt[0] = (fir_value +
     * 32) - 87; } else if (fir_value >= 48 && fir_value <= 57) { tempInt[0] =
     * fir_value - 48; } else { return false; } sum += factor[0] *
     * tempInt[0];
     *
     * if (sec_value >= 65 && sec_value <= 90) { tempInt[1] = (sec_value -
     * 65) + 10; } else if (sec_value >= 48 && sec_value <= 57) { tempInt[1] =
     * sec_value - 48; } else { return false; } sum += factor[1] *
     * tempInt[1];
     *
     */

    for (int j = 0; j < 8; j++) {
        if (orgCode.charAt(j) >= 65 && orgCode.charAt(j) <= 90) {
            tempInt[j] = orgCode.charAt(j) - 65 + 10;
        } else if (orgCode.charAt(j) >= 48 && orgCode.charAt(j) <= 57) {
            tempInt[j] = orgCode.charAt(j) - 48;
        } else {
            return false;
        }
        sum += factor[j] * tempInt[j];
    }

    // ??
    int balance = 11 - sum % 11;

    // ???
    int last_value = orgCode.charAt(9);

    // ?
    if (!((last_value == 88 && balance == 10) // ?1?'X'?10
            || (balance == 11 && last_value == 48) // ?211?'0'
            || balance == last_value - 48 // ?3balance == last_value -
    // 48
    )) {
        return false;
    }

    return true;
}

From source file:mobi.jenkinsci.net.UrlPath.java

/**
 *
 * @param __path The path to compare with this path
 * @return True if the given path full matches this path
 *///w w  w.j  a v a 2  s  .  c om
public boolean isPath(final String __path) {

    final String pattern = "/?" + __path + "/?";
    return Pattern.matches(pattern, path);
}

From source file:com.predic8.membrane.core.interceptor.rest.REST2SOAPInterceptor.java

private Mapping findFirstMatchingRegEx(String uri) {
    for (Mapping m : mappings) {
        if (Pattern.matches(m.regex, uri))
            return m;
    }/*from   ww  w.  j a v a2  s.  c  o  m*/
    return null;
}

From source file:com.beem.project.beem.ui.wizard.CreateAccountFragment.java

/**
 * Check the format of the email./*from w ww . j  a  va 2 s  . co  m*/
 *
 * @return true if the email is valid.
 */
private boolean checkUserName() {
    String email = username.getText().toString();
    return Pattern.matches("[a-zA-Z0-9._%+-]+", email);
}