[Bese-devel] validators and null values

Nathan Bird nathan at acceleration.net
Thu Apr 27 20:54:28 UTC 2006


Proposed idea I wanted to toss out there for people to chew over while I'm
working on code for it:

Most of the validators are already setup to return T, indicating valid, when
given a nil value. The idea being that if you want to require a value then
use a not-empty-validator as well.

Introduce a "value-validator" subclass of validator that becomes the
superclass of most of the current validators. The :around validate for this
does the appropriate null check, and only applies the validator if there is
a value to test. I think this would apply to the following:
* regex validator (new)
  * email validator
  * phone validator (new)
* is-a-number-validator
* number-range-validator (note, currently the javascript allows null, the
server-side validate does not)
* is-an-integer-validator
* integer-range-validator
* string=-validator (server check does not allow for both boxes to be empty,
javascript does)

Really the only validator I don't think would fall under this right now is
the not-empty-validator.

I think there could potentially be other validators that would also inherit
directly from validator and would want to be called regardless of whether
the input value is null. A contrived example for this other validator is a
password box that can be empty iff a cookie or something is set.

I think there is cause for introducing a type, eg. value-validator, to
designate this class of validators who are not checked unless there is
actually a value.

I'm going to code up an implementation (shouldn't be too tough) and commit
it to ucw-public unless someone objects/has a better idea?






More information about the bese-devel mailing list