Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 62422 invoked from network); 9 Dec 2006 03:30:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Dec 2006 03:30:35 -0000 Received: (qmail 5709 invoked by uid 500); 9 Dec 2006 03:30:40 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 5640 invoked by uid 500); 9 Dec 2006 03:30:40 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 5629 invoked by uid 500); 9 Dec 2006 03:30:40 -0000 Received: (qmail 5626 invoked by uid 99); 9 Dec 2006 03:30:40 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Dec 2006 19:30:40 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Dec 2006 19:30:31 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 9AF8D1A9846; Fri, 8 Dec 2006 19:29:48 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r484904 - in /jakarta/commons/proper/validator/trunk: src/share/org/apache/commons/validator/routines/RegexValidator.java src/share/org/apache/commons/validator/routines/package.html xdocs/changes.xml Date: Sat, 09 Dec 2006 03:29:48 -0000 To: commons-cvs@jakarta.apache.org From: niallp@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061209032948.9AF8D1A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: niallp Date: Fri Dec 8 19:29:47 2006 New Revision: 484904 URL: http://svn.apache.org/viewvc?view=rev&rev=484904 Log: Update release notes, routines documentation and few JavaDoc corrections Modified: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/RegexValidator.java jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/package.html jakarta/commons/proper/validator/trunk/xdocs/changes.xml Modified: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/RegexValidator.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/RegexValidator.java?view=diff&rev=484904&r1=484903&r2=484904 ============================================================================== --- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/RegexValidator.java (original) +++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/RegexValidator.java Fri Dec 8 19:29:47 2006 @@ -21,12 +21,12 @@ import java.util.regex.Matcher; /** - * Regular Expression validator (using JDK 1.4+ regex support). + * Regular Expression validation (using JDK 1.4+ regex support). *

* 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

*
    *
  • Validate 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 @@
     
  • 3.5 Currency Validation
  • 3.6 Percent Validation
  • +
  • 2. Other Validators +
  • @@ -399,6 +405,176 @@ also support percent validation. However, since they don't allow fractions they will only work with percentages greater than 100%.

    + + +

    4. Other Validators

    + + +

    4.1 Overview

    +

    + This section lists other available validators. +

    +
      +
    • Regular Expressions - validates + using Java 1.4+ regular expression support
    • +
    • Check Digit - validates/calculates + check digits (i.e. EAN/UPC, credit card, ISBN).
    • +
    + + +

    4.2 Regular Expression Validation

    +

    + 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. +

    +
      +
    • Method Flavours - three flavours of validation metods are provided:
    • +
        +
      • 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.
      • +
      +
    • Case Sensitivity - matching can be done in either a case + sensitive or case in-sensitive way.
    • +
    • Multiple Expressions - instances of the + RegexValidator + can be created to either match against a single regular expression + or set (String array) of regular expressions.
    • +
    +

    + 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. +

    + + +

    4.3 Check Digit validation/calculation

    +

    + 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);
    +
    +
    + Modified: jakarta/commons/proper/validator/trunk/xdocs/changes.xml URL: http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/xdocs/changes.xml?view=diff&rev=484904&r1=484903&r2=484904 ============================================================================== --- jakarta/commons/proper/validator/trunk/xdocs/changes.xml (original) +++ jakarta/commons/proper/validator/trunk/xdocs/changes.xml Fri Dec 8 19:29:47 2006 @@ -40,6 +40,15 @@ + + New Regular Expression validator using JDK 1.4's Regex - see + RegexValidator. + + + Factor out Check Digit logic into separate implementations. A + new CheckDigit type has been added with a number + of implementations. + Upgrade to Digester 1.8 --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org