[TYPO3-english] Validate input field in TYPO3 BE

Rayuth You rayuth.you at gmail.com
Thu May 5 04:11:30 CEST 2011


Hi Steffen

I already post this article again in typo3v4mvc.
I used to validate in FE, it worked well but it's not work in BE module.
Need I do something in TCA or not?

Thanks
Yuth

On 05/05/2011 01:37 AM, Steffen Müller wrote:
> Hi.
>
> On 03.05.2011 12:14 Rayuth You wrote:
>> Hi all
>>
>> I use typo3 4.5, I want to validate my field in BE with regular
>> expression. I tried in model with @validate RegularExpression(). But it
>> not work.
>>
>
> You use extbase, right? Next time ask in the typo3.projects.typo3v4mvc
> list.
>
> What arguments did you use in RegularExpression()?
>
> You should put the regex pattern into the clauses, e.g.
>
> /**
> * @var string $title
> * @validate RegularExpression('/[a-z]+/')
> */
> protected $title;
>
> ... will result in:
> preg_match('/[a-z]+/', $title);
>
>
> You can of course write a validator by yourself. e.g. if you need the
> regex repeatedly or you want to hide complexity in your model. Find an
> example in SjrOffers extension in forge:
>
>
> Model:
> ----------
>
> class Tx_SjrOffers_Domain_Model_AttendanceFee extends
> Tx_Extbase_DomainObject_AbstractEntity {
>
> /**
> * @var string The amount.
> * @validate Tx_SjrOffers_Domain_Validator_AmountValidator
> **/
> protected $amount = '0.00';
>
> http://forge.typo3.org/projects/extension-sjr_offers/repository/entry/trunk/Classes/Domain/Model/AttendanceFee.php
>
>
>
>
> Validator:
> --------------
>
> class Tx_SjrOffers_Domain_Validator_AmountValidator extends
> Tx_Extbase_Validation_Validator_AbstractValidator {
>
> /**
> * Returns TRUE, if the given value is a valid amount.
> *
> * If at least one error occurred, the result is FALSE.
> *
> * @param mixed $value The value that should be validated
> * @return boolean TRUE if the value is an amount, otherwise FALSE
> */
> public function isValid($value) {
> $this->errors = array();
> if (preg_match("/^([0-9]{1,3}(\.[0-9]{3})*(,[0-9]+)?|,[ 0-9]+)$/",
> $input, $matches)) {
> return TRUE;
> }
> }
> }
>
>
> http://forge.typo3.org/projects/extension-sjr_offers/repository/entry/trunk/Classes/Domain/Validator/AmountValidator.php
>
>
>


More information about the TYPO3-english mailing list