I am Refactoring some code while doing I found Zend_Validate_Regex directly use in the code

$validator = new \Zend_Validate_Regex(['pattern' => '/^[a-z][a-z_0-9]{0,29}[a-z0-9]$/']);

I want suggestions from Magento Community is there any interface in Magneto Framework to use

if No, is this recommended to this class directly?

Thank You


You could use this class : vendor/magento/framework/Validator/Regex.php. But it is empty and extends Zend_Validate_Regex and Magento itself do not necessarily use this class. In the core you can see a lot of validation made like this one in vendor/magento/module-backend/Model/Menu/Item/Validator.php:

$resourceValidator = new \Zend_Validate();
        $resourceValidator->addValidator(new \Zend_Validate_StringLength(['min' => 8]));
            new \Zend_Validate_Regex('/^[A-Z][A-Za-z0-9]+_[A-Z][A-Za-z0-9]+::[A-Za-z_0-9]+$/')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.