Return-Path:
* This validator provides convenient regular expression validation
* in one of two ways:
*
- * 1. One Off validation using the static methods
+ *
1. One Off validation using the static methods
*
*
*
- * true
or false
:
@@ -45,11 +45,11 @@
*
* 2. Re-using cached instances validating against one or more regular expression
+ *
2. Re-using cached instances validating against one or more regular expression
* Construct the validator either for a single regular expression or a set (array) of
* regular expressions. By default validation is case sensitive but constructors
* are provided to allow case in-sensitive validation. For example to create
- * a validator which does case in-sensitive validation for a set of regular
+ * a validator which does case in-sensitive validation for a set of regular
* expressions:
*
* String[] regexs = new String[] {...};
Modified: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/package.html?view=diff&rev=484904&r1=484903&r2=484904
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/package.html (original)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/package.html Fri Dec 8 19:29:47 2006
@@ -41,6 +41,12 @@
+
+ This section lists other available validators. +
++ Regular expression validation can be done either by using the static + methods provied by RegexValidator or + by creating a new instance, which caches and re-uses compiled Patterns. +
+isValid()
methods return true/false to indicate
+ whether validation was successful.validate()
methods return a String
+ value of the matched groups aggregated together or
+ null
if invalid.match()
methods return a String
array
+ of the matched groups or null
if invalid.+ Below is an example of using one of the static methods to validate, + matching in a case insensitive manner and returning a String + of the matched groups (which doesn't include the hyphen). +
++ // set up the parameters + boolean caseSensitive = false; + String regex = "^([A-Z]*)(?:\\-)([A-Z]*)$"; + + // validate - result should be a String of value "abcdef" + String result = RegexValidator.validate("abc-def", regex, caseSensitive); + ++ +
The following static methods are provided for regular expression validation: +
+isValid(value, regex)
isValid(value, regex, caseSensitive)
validate(value, regex)
validate(value, regex, caseSensitive)
match(value, regex)
match(value, regex, caseSensitive)
+ Below is an example of creating an instance of + RegexValidator matching in a case insensitive + manner against a set of regular expressions: +
++ // set up the parameters + boolean caseSensitive = false; + String regex1 = "^([A-Z]*)(?:\\-)([A-Z]*)*$" + String regex2 = "^([A-Z]*)$"; + String[] regexs = new String[] {regex1, regex1}; + + // Create the validator + RegexValidator validator = new RegexValidator(regexs, caseSensitive); + + // Validate true/false + boolean valid = validator.isValid("abc-def"); + + // Validate and return a String + String result = validator.validate("abc-def"); + + // Validate and return a String[] + String[] groups = validator.match("abc-def"); + ++
See the + RegexValidator javadoc for a full list + of the available constructors. +
+ + ++ CheckDigit defines a new + type for the calculation and validation of check digits with the + following methods: +
+isValid(code)
- validates the check digit of a code,
+ returning true
or false
.calculate(code)
- calulates the check digit for a code
+ returning the check digit character.+ The following implementations are provided: +
++ The following examples show validating the check digit of a code: +
++ + // Luhn check digit validation + boolean valid = LuhnCheckDigit.INSTANCE.isValid(code); + + // EAN / UPC / ISBN-13 check digit validation + boolean valid = EAN13CheckDigit.INSTANCE.isValid(code); + + // ISBN-10 check digit validation + boolean valid = ISBNCheckDigit.ISBN10.isValid(code); + boolean valid = ISBN10CheckDigit.INSTANCE.isValid(code); + + // ISBN-13 check digit validation + boolean valid = ISBNCheckDigit.ISBN13.isValid(code); + + // ISBN-10 or ISBN-13 check digit validation + boolean valid = ISBNCheckDigit.ISBN.isValid(code); + ++
+ The following examples show calulating the check digit of a code: +
++ + // Luhn check digit validation + char checkdigit = LuhnCheckDigit.INSTANCE.calculate(code); + + // EAN / UPC / ISBN-13 check digit validation + char checkdigit = EAN13CheckDigit.INSTANCE.calculate(code); + + // ISBN-10 check digit validation + char checkdigit = ISBNCheckDigit.ISBN10.isValid(code); + char checkdigit = ISBN10CheckDigit.INSTANCE.calculate(code); + + // ISBN-13 check digit validation + char checkdigit = ISBNCheckDigit.ISBN13.calculate(code); + + // ISBN-10 or ISBN-13 check digit validation + char checkdigit = ISBNCheckDigit.ISBN.calculate(code); + ++