org.enhydra.barracuda.core.forms.validators
Class DigitValidator

java.lang.Object
  extended byorg.enhydra.barracuda.core.forms.AbstractFormValidator
      extended byorg.enhydra.barracuda.core.forms.DefaultFormValidator
          extended byorg.enhydra.barracuda.core.forms.validators.DigitValidator
All Implemented Interfaces:
FormValidator

public class DigitValidator
extends DefaultFormValidator

This validator ensures that the value contains only digits tested against the field size length (len). If the value's length is not equal to the length or a character other than the numbers 0-9 is found, an exception will be throw.

This class can be used 3 ways

1) As a digit validator, confirming that only digits exist for the value. The field value "is not required", and will only be tested for digits when the field value "is not null". Use default constructor() or constructor(errorMessage) for this case.

2) As a digit/length validator where phoneNumber will default to false. This can be used to test set lengths of digits (credit cards, quantities, soc sec numbers etc.) The field value "is required". Use constructor(len) for this case.

3) As a phone number validator (domestic/international) where certain phone number rules apply. Use constructor(len, isDomesticPhone, errMessage) for this case.

Note: There is no current support for '.' or '-' in the value for phone numbers.

This class works very nicely where the input fields are separated into their respective types (i.e Separating a Domestic Phone Number into 3 'input type=text' boxes -- Area Code len=3, Prefix len = 3, and Number len =4) will permit easier implementation of the rules as more are added.

Rules:
--domesticPhone = true
if length = 3, then the value may not start with a zero (0)
--domesticPhone = false (international)
none

Since:
1.0
Version:
%I%, %G%
Author:
Paul G. Markovich , Christian Cryder [christianc@granitepeaks.com], Jacob Kjome , Bill Wallace , Diez B. Roggisch

Field Summary
protected  boolean domesticPhone
           
protected  int len
           
protected  boolean phoneNumber
           
protected  boolean requireLength
           
 
Fields inherited from class org.enhydra.barracuda.core.forms.DefaultFormValidator
localLogger, validators
 
Constructor Summary
DigitValidator()
          Public constructor.
DigitValidator(int ilen)
          Public constructor.
DigitValidator(int ilen, boolean idomesticPhone, String ierrmsg)
          Public constructor.
DigitValidator(int ilen, String ierrmsg)
          Public constructor.
DigitValidator(String ierrmsg)
          Public constructor.
 
Method Summary
 boolean isDomesticPhone()
          Return true if this must be a domestic phone#
 void validateFormElement(Object val, FormElement element, boolean deferExceptions)
          Validate a FormElement to make see if the element equals() a given object
 
Methods inherited from class org.enhydra.barracuda.core.forms.DefaultFormValidator
addValidator, getValidators, removeValidator, validate, validateForm, validateFormElement
 
Methods inherited from class org.enhydra.barracuda.core.forms.AbstractFormValidator
generateException, getErrorMessage, isNull, setErrorMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

len

protected int len

requireLength

protected boolean requireLength

phoneNumber

protected boolean phoneNumber

domesticPhone

protected boolean domesticPhone
Constructor Detail

DigitValidator

public DigitValidator()
Public constructor.


DigitValidator

public DigitValidator(String ierrmsg)
Public constructor.

Parameters:
ierrmsg - the message associated with this validation error

DigitValidator

public DigitValidator(int ilen)
Public constructor. Utilizing this constructor, the field value will be required

Parameters:
ilen - the length of the field to validate all digits

DigitValidator

public DigitValidator(int ilen,
                      String ierrmsg)
Public constructor.

Parameters:
ilen - the length of the field to validate all digits
ierrmsg - the message associated with this validation error

DigitValidator

public DigitValidator(int ilen,
                      boolean idomesticPhone,
                      String ierrmsg)
Public constructor.

Parameters:
ilen - the length of the field to validate all digits
idomesticPhone - when true will validate based on domestic rules. At this time the only rule is for a length of 3 (area codes/prefixes) that the value can't start with 0
ierrmsg - the message associated with this validation error
Method Detail

isDomesticPhone

public boolean isDomesticPhone()
Return true if this must be a domestic phone#

Returns:
boolean true if domestic phone#

validateFormElement

public void validateFormElement(Object val,
                                FormElement element,
                                boolean deferExceptions)
                         throws ValidationException
Validate a FormElement to make see if the element equals() a given object

Overrides:
validateFormElement in class DefaultFormValidator
Parameters:
val - the value to compare the element value to
element - the form element that contains the val to validate elements by comparing them with other elements)
deferExceptions - do we want to deferValidation exceptions and attempt to validate all elements so that we can process all the exceptions at once
Throws:
ValidationException - if the element is not valid


Copyright © 2003 BarracudaMVC.org All Rights Reserved.