4
votes

Realized few minutes ago that there is no GreaterOrEqualThan validator, or a parameter in GreaterThan validator that changes its behaviour from > to >=.

Why? Is it possible to compose >= validator using basic zend framework set of validators?

Yes, guys, I know that I can write my own validator, but I'm curious about solution based on native ZF validators ;-)

1
What do you want to compare with GreaterOrEqualThan or GreaterThan? I think zend framework implementation ends at some point because it's still a framework that needs to be customized for your needs. However interesting question ;) - Upvote
I created my own GT and LT validators that accept a 'strict' option. - David Weinraub
@ArtWorkAD: well, some zend validators accepts additional parameters that control the validator behaviour. Such as "strict" parameter for identical, "allowWhiteSpace" for alnum, "inclusive" (!!!!!!!) for between, etc. So it is "inclusive" for between, but no such option for greaterThan. It is not fair ;-) - zerkms
@David Weinraub: Yeah, it is easy. My question is just kind of curiosity, may be some one here know what idea they followed. - zerkms

1 Answers

3
votes

I'd set array('min' => ($value-1)) and use GreaterThan. Maybe use a chain and add Digits, so you make sure you're dealing with numbers. Something like this:

$value = 10;

$chain = new Zend_Validate();
$chain->addValidator(new Zend_Validate_Digits());
$chain->addValidator(new Zend_Validate_GreaterThan(array('min' => ($value-1))));

var_dump($chain->isValid($value), $chain->getMessages());

I think that's as far as you get with ZF. Wouldn't hurt to get a feature request though. Would be a nice addition. Otherwise, extend GreaterThan and add an option.