本文整理汇总了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"));
}
示例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);
}
示例3: UrlUtils
import org.apache.commons.validator.routines.RegexValidator; //导入依赖的package包/类
public UrlUtils() {
this.urlValidator = new UrlValidator(new RegexValidator(".*"), 0L);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
}