You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Thomas Werthmann-Auzinger <th...@prudential.com> on 2000/10/04 22:43:03 UTC

Reusing Xerces code for validating patterns


Hi,

we'd like to reuse the patterns we defined in our XML datatypes for validating
data entered via the GUI, on a keystroke by keystroke basis. E.g., we defined:

  <xsd:simpleType name="FaxNumberType" base="xsd:string">
    <xsd:pattern value="[\d] {3} + -  [\d] {3} + - [\d] {4}"/>
  </xsd:simpleType>

  <xsd:element name="deliveryFaxNumber" type="FaxNumberType"/>


What we would like to have is a class that takes the pattern and a string and
tells us whether that string is valid, invalid, or incomplete, but so far not
invalid.

E.g.: "212-" is incomplete, but not invalid. "212121" is invalid. "212-555-1212"
is valid and complete.

I would like to have a class XercesPatternValidator that I could use in a
fashion as shown in the pseudocode below:

class FaxNumberType {
  public static final int VALID = 0;
  public static final int INVALID = 1;
  public static final int INCOMPLETE_BUT_NOT_INVALID = 3;

  String  value;
  String pattern = "[\d] {3} + -  [\d] {3} + - [\d] {4}";

  public void setValue(String value);

  public int validate() {
    XercesPatternValidator xpv = new XercesPatternValidator();
    if(xpv.isComplete(pattern, value) {
      if(xpv.isValid(pattern, value) {
        return VALID;
      } else {
        return INVALID;
      }
    } else {
      if(xpv.isValid) {
        return INCOMPLETE_BUT_NOT_INVALID;
      } else {
        return INVALID;
      }
    }
  }
}

Is this possible inprinciple? What are the classes/interfaces we'd have to use
for that?

Thanks,

Thomas