On Wed, Oct 1, 2008 at 2:53 AM, Per Jessen <[EMAIL PROTECTED]> wrote:
> Frank Stanovcak wrote:
>
>> I've got to pass about 9 or 10 calls to it, some of which will be
>> arrays, and I have to do it from several different places.  Felt this
>> was a bit more elegant than hard coding the pregmatches unless there
>> is an  easier way.
>
> Code elegance is usually in the eye of the beholder, but personally I
> would have stuck to a set of hardcoded preg_matches().
>
>
> /Per Jessen, Zürich

Just to throw out another option...  I use a little input filter
validation library I wrote.  I wanted to use something pre-existing
but I was stuck on php4 at the time so I modeled it after a few
different frameworks, specifically stubbles & solar.

Basically it works by creating classes that are filters.  These
filters can be applied to any variable and they will either return the
variable upon validation success, null on failure, or a user defined
override default.  Along with the filters are some helpers to create
composite filters to do simple AND's & OR's.  I also have another one
for applying a filter to an array.  There are also hooks into the
request object to apply these validation filters.

If I were to handle this case I could do this:

$array = $request->getFiltered(new my_InputFilter_ValidateArray(new
my_InputFilter_ValidateRegex('/regex/')), 'postkey',
my_Request::POST);

ValidateArray recursively applies the passed filter to all entries in
the array making sure the value matches.

Reply via email to