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 9030169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:25:25+00:00 2026-06-16T07:25:25+00:00

I’m developing a registration page using Zend Framework. Phone, Mobile, ID Number are the

  • 0

I’m developing a registration page using Zend Framework.

Phone, Mobile, ID Number are the fields I’d like to Validate. So far I have a validation only for Not Empty.

I couldn’t find the right solution so maybe you can help me out.

I want the phone and mobile fields to be only integers for ex. 12345667 and to have specific length, for ex. minimum 7 digits.

and the same thing goes with ID NUMBER field too.

This is how it looks right now:

$phone = new Zend_Form_Element_Text('phone');
$phone->setLabel('Phone')
      ->setAttribs(array('class' => 'inputtext'))       
      ->setOptions(array('size' => '50'))       
      ->setRequired(false)
      ->addFilter('StripTags')
      ->addFilter('StringTrim')
      ->addValidator('NotEmpty');   
  • 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-06-16T07:25:26+00:00Added an answer on June 16, 2026 at 7:25 am

    Let’s try and give you some answer for your question.

    If you don’t already realize it the validators in Zend_Form are the same validators used as standard validators in Zend_Validate, you usually just use the class name as a string instead of calling new. The same is true for filters and Zend_Filter

    The closest standard validator available for a phone number would be the ‘Digits’ validator.

    $phone = new Zend_Form_Element_Text('phone');
    $phone->setLabel('Phone')
          ->setAttribs(array('class' => 'inputtext'))       
          ->setOptions(array('size' => '50'))       
          ->setRequired(false)
          ->addFilter('StripTags')
          ->addFilter('StringTrim')
          ->addValidator('NotEmpty');
    //add digits validator , closest available to phone number in standard validators;
    $phone->addValidator('Digits');
    

    However you may find it more appropriate to construct your own validator by extending Zend_Validate_Abstract. A phone number validator might look like:

    //validates US phone numbers using Zend_Validator_Regex
    class MyNamespace_Validator_Form_Usphone extends Zend_Validate_Abstract
    {
        const PHONE = 'phone';
    
        protected $_messageTemplates = array(
            self::PHONE => "'%value%' is not a valid U.S. phone number.
                Phone number must be entered in (xxx)xxx-xxxx or xxx-xxx-xxxx format."
        );
    
        public function isValid($value)
        {
            $this->_setValue($value);
    
            $isValid = true;
            $pattern = ('/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/');
            if (!preg_match($pattern, $value)) {
                $this->_error(self::PHONE);
                $isValid = false;
            }
            return $isValid;
        }
    }
    

    and would be used in your form element:

    $phone->addValidator(new MyNamespace_Validator_Form_Usphone());
    

    One thing to keep in mind: If you set a form element as 'Required' using the 'NotEmpty' validator is redundant in most cases as setRequired() calls 'NotEmpty' internally.

    Also remember that typically in Zend_Form filters are applied prior to validation.

    Hope this helps.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have thousands of HTML files to process using Groovy/Java and I need to
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

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.