[TYPO3-50-general] optional or nested validators

Robert Lemke robert at typo3.org
Mon Oct 12 10:08:46 CEST 2009


Hi Pascal,

Am 08.10.2009 um 18:58 schrieb Pascal Jungblut:

> I'm curious about the validation feature. Let's assume I have an
> optional field in fe_users (e.g. 'zip'). I want the user to enter
> either nothing _or_ a five-digit number. As I see it, there is
> currently no possibility to use the DisjunctionValidator that would
> allow something like:
>
> ---
> @validate Empty, StringLength(minimum = 5, maximum = 5)
> ---
>
> So if I think one step further I would want to combine the
> DisjunctionValidator and ConjunctionValidator or even nest them:
>
> ---
> @validate OR(Empty, AND(String, StringLength(minimum = 3, maximum =  
> 5)))
> ---
>
> Of course, I could write a new validator for that but it would reduce
> code-redundancy if one were able to nest the validators.
>
> Is this already possible? If not: how would you validate something
> that is optional?

The easiest way to define an optional argument is to define an  
optional argument:

/**
  * @param string $password The password
  * @validate StringLength(minimum = 5, maximum = 30)
  */
public function someAction($password = NULL) {
   ...
}

Cheers,
robert



More information about the TYPO3-project-5_0-general mailing list