|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.barracudamvc.core.forms.AbstractFormValidator
org.barracudamvc.core.forms.DefaultFormValidator
org.barracudamvc.core.forms.validators.DigitValidator
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
Field Summary | |
protected boolean |
domesticPhone
|
protected int |
len
|
protected boolean |
phoneNumber
|
protected boolean |
requireLength
|
Fields inherited from class org.barracudamvc.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.barracudamvc.core.forms.DefaultFormValidator |
addValidator, getValidators, removeValidator, validate, validateForm, validateFormElement |
Methods inherited from class org.barracudamvc.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 |
protected int len
protected boolean requireLength
protected boolean phoneNumber
protected boolean domesticPhone
Constructor Detail |
public DigitValidator()
public DigitValidator(String ierrmsg)
ierrmsg
- the message associated with this validation errorpublic DigitValidator(int ilen)
ilen
- the length of the field to validate all digitspublic DigitValidator(int ilen, String ierrmsg)
ilen
- the length of the field to validate all digitsierrmsg
- the message associated with this validation errorpublic DigitValidator(int ilen, boolean idomesticPhone, String ierrmsg)
ilen
- the length of the field to validate all digitsidomesticPhone
- 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 0ierrmsg
- the message associated with this validation errorMethod Detail |
public boolean isDomesticPhone()
public void validateFormElement(Object val, FormElement element, boolean deferExceptions) throws ValidationException
validateFormElement
in class DefaultFormValidator
val
- the value to compare the element value toelement
- 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
ValidationException
- if the element is not valid
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |