当前位置: 首页>>代码示例>>Java>>正文


Java RegexValidator类代码示例

本文整理汇总了Java中org.apache.commons.validator.routines.RegexValidator的典型用法代码示例。如果您正苦于以下问题:Java RegexValidator类的具体用法?Java RegexValidator怎么用?Java RegexValidator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RegexValidator类属于org.apache.commons.validator.routines包,在下文中一共展示了RegexValidator类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testValidation

import org.apache.commons.validator.routines.RegexValidator; //导入依赖的package包/类
@Test
public void testValidation() throws Exception {
     RegexValidator regex = new RegexValidator(new String[]{"http","https","((localhost)(:[0-9]+))",".*\\.linux-server(:[0-9]+)"});
     UrlValidator validator = new UrlValidator(regex, 0);
     assertTrue("localhost URL should validate",
               validator.isValid("http://localhost:8080/demogadgets/CTSSResourcesMapView.xml"));
       assertTrue("127.0.0.1 should validate",
               validator.isValid("http://127.0.0.1:8080/demogadgets/CTSSResourcesMapView.xml"));
       assertTrue("my.linux-server should validate",
               validator.isValid("http://my.linux-server:8080/demogadgets/CTSSResourcesMapView.xml"));

       assertFalse("broke.my-test should not validate",
               validator.isValid("http://broke.my-test/test/index.html"));

       assertTrue("www.apache.org should still validate",
               validator.isValid("http://www.apache.org/test/index.html"));
   }
 
开发者ID:apache,项目名称:rave,代码行数:18,代码来源:WidgetValidatorTest.java

示例2: Validator

import org.apache.commons.validator.routines.RegexValidator; //导入依赖的package包/类
/**
 * Creates the validator
 * @param cc the country code
 * @param len the length of the IBAN
 * @param format the regex to use to check the format
 */
public Validator(String cc, int len, String format) {
    if (!(cc.length() == 2 && Character.isUpperCase(cc.charAt(0)) && Character.isUpperCase(cc.charAt(1)))) {
        throw new IllegalArgumentException("Invalid country Code; must be exactly 2 upper-case characters");
    }
    if (len > MAX_LEN || len < MIN_LEN) {
        throw new IllegalArgumentException("Invalid length parameter, must be in range "+MIN_LEN+" to "+MAX_LEN+" inclusive: " +len);
    }
    if (!format.startsWith(cc)) {
        throw new IllegalArgumentException("countryCode '"+cc+"' does not agree with format: " + format);
    }
    this.countryCode = cc;
    this.lengthOfIBAN = len;
    this.validator = new RegexValidator(format);
}
 
开发者ID:ManfredTremmel,项目名称:gwt-commons-validator,代码行数:21,代码来源:IBANValidator.java

示例3: UrlUtils

import org.apache.commons.validator.routines.RegexValidator; //导入依赖的package包/类
public UrlUtils() {
  this.urlValidator = new UrlValidator(new RegexValidator(".*"), 0L);
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:4,代码来源:UrlUtils.java

示例4: isValidMac

import org.apache.commons.validator.routines.RegexValidator; //导入依赖的package包/类
public static boolean isValidMac(final String macAddr) {
    final RegexValidator mv = new RegexValidator("^(?:[0-9a-f]{1,2}([-:\\.]))(?:[0-9a-f]{1,2}\\1){4}[0-9a-f]{1,2}$", false);
    return mv.isValid(macAddr);
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:5,代码来源:NetUtils.java

示例5: isValid

import org.apache.commons.validator.routines.RegexValidator; //导入依赖的package包/类
@Override
public boolean isValid(final String text, String attribute) {
    String regex = ruleAnnotation.regex();
    boolean caseSensitive = ruleAnnotation.caseSensitive();
    return new RegexValidator(regex, caseSensitive).isValid(text);
}
 
开发者ID:liraz,项目名称:gwt-backbone,代码行数:7,代码来源:PatternRule.java

示例6: WidgetValidator

import org.apache.commons.validator.routines.RegexValidator; //导入依赖的package包/类
public WidgetValidator() {
    super();
    RegexValidator regex = new RegexValidator(new String[] {"http", "https","((localhost)(:[0-9]+))"});
    urlValidator = new UrlValidator(regex, 0);
}
 
开发者ID:apache,项目名称:rave,代码行数:6,代码来源:WidgetValidator.java

示例7: isValidMac

import org.apache.commons.validator.routines.RegexValidator; //导入依赖的package包/类
public static boolean isValidMac(final String macAddr) {
        RegexValidator mv = new RegexValidator("^(?:[0-9a-f]{1,2}([-:\\.]))(?:[0-9a-f]{1,2}\\1){4}[0-9a-f]{1,2}$", false);
        return mv.isValid(macAddr);
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:5,代码来源:NetUtils.java

示例8: UrlValidator

import org.apache.commons.validator.routines.RegexValidator; //导入依赖的package包/类
/**
 * Customizable constructor. Validation behavior is modifed by passing in
 * options.
 * 
 * @param schemes
 *            the set of valid schemes
 * @param authorityValidator
 *            Regular expression validator used to validate the authority
 *            part
 * @param options
 *            Validation options. Set using the public constants of this
 *            class. To set multiple options, simply add them together:
 *            <p>
 *            <code>ALLOW_2_SLASHES + NO_FRAGMENTS</code>
 *            </p>
 *            enables both of those options.
 */
public UrlValidator(String[] schemes, RegexValidator authorityValidator,
        long options) {
    this.options = options;

    if (isOn(ALLOW_ALL_SCHEMES)) {
        this.allowedSchemes = Collections.emptySet();
    } else {
        if (schemes == null) {
            schemes = DEFAULT_SCHEMES;
        }
        this.allowedSchemes = new HashSet<String>();
        this.allowedSchemes.addAll(Arrays.asList(schemes));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm-app,代码行数:32,代码来源:UrlValidator.java


注:本文中的org.apache.commons.validator.routines.RegexValidator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。