Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5954817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:01:30+00:00 2026-05-22T18:01:30+00:00

I have a Zend_Form_element: $text=new Zend_Form_Element_Text(‘text’); I added a regex validator to it: $text->addValidator(‘regex’,

  • 0

I have a Zend_Form_element:

$text=new Zend_Form_Element_Text('text');

I added a regex validator to it:

$text->addValidator('regex', false, array('/[\\?\\&]v=([^\\?\\&]+)/'));

How could I set a customized error message for the validator?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:01:31+00:00Added an answer on May 22, 2026 at 6:01 pm

    You can add custom validation error messages if you know what specific error codes the validator provides. In case of regex, I believe it gives an “regexNotMatch” error, so for this particular case, you could use:

    $text->addValidator('regex', false, array(
        '/[\\?\\&]v=([^\\?\\&]+)/',
        'messages'=>array(
        'regexNotMatch'=>'There was some random custom error'
        )    
    ));
    

    For more information, have a look here.

    Some developers may wish to provide custom error messages for a validator. The $options argument of the Zend_Form_Element::addValidator() method allows you to do so by providing the key ‘messages’ and mapping it to an array of key/value pairs for setting the message templates. You will need to know the error codes of the various validation error types for the particular validator

    Similar question here and here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the next element: $email = new Zend_Form_Element_Text('email'); $email->setAttribs(array('class' => 'input-text', 'id' =>
In normal html, we could have an array field like person[] <input name=person[] type=text
I have this simplified form: $this->form = new \Zend_Form(); $this->form->setAction($request->currentPath()); $this->form->setMethod('post'); $this->form->addElement('text', 'firstName', array(
I have a Form element: $Form=new Zend_Form; $Form->setAction($this->view->url(array('controller'=>'auth','action'=>'create'),null,true)) ->setMethod('post') ->setAttrib('id','auth-form') ->removeAttrib('enctype'); As can be
In a form, I have the following element: $email = new Zend_Form_Element_Text('username'); $email ->setLabel($this->getView()->l('E-mail'))
I have a Zend_Form with file element like this: ->addElement('file', 'image', array( 'required' =>
I have a button element that I've created like so: $submit = new Zend_Form_Element_Button('submit');
Here I have a password field: /*********************PASSWORD**********************/ $password = new Zend_Form_Element_Password('password'); $alnumValidator = new
I have a simple content edit form (Zend_Form) that I populate() with an array
By default Zend Form Text elements don't have a width specified. Textarea elements have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.